我正在尝试在 Glassfish 3.1 上评估 CDI,尽管我已经成功使其正常工作,但当我尝试将代码拆分为单独的部署模块时,我收到了一个奇怪的错误。更具体地说:
我在同一个实用程序项目中捆绑了两个类(假设为 CommonLib.jar);类名是 UserDatabase
和 UserDatabaseEntityManager
,它们的定义如下(在本消息末尾的 PS 中)。
我还有一个带有 EJB3.1 模块的 EAR。
当我选择将 CommonLib.jar 部署为 EAR 的“捆绑库”时,出现以下错误:
部署期间发生错误:加载应用程序时出现异常:WELD-001408
类型 [EntityManager
] 与限定符 [@UserDatabase
] 的依赖关系不满足] 在注入点 [[field] @UserDatabase @Inject com.test.TestEJB.itemPersistenceEm
]。请参阅 server.log
了解更多详细信息。
当我将 CommonLib.jar 部署为共享库(在 $glasshfish_installation_path/domains/domain1/lib 下复制的 jar 文件)时,我也会遇到与上面相同的错误
但是,如果我选择在 EJB 项目中只包含两个类(UserDatabase
和 UserDatabaseEntityManager
)(因此它们在 EJB 模块内编译),那么注入工作正常。
我面临类加载器问题吗?有什么想法可以解决这个问题吗?
I'm trying to evaluate CDI on Glassfish 3.1 and even though I have accomplished to make it work well, when I'm trying to split my code in separate deployment modules I get a weird error. More specifically:
I have two classes bundled in the same utility project (let's say the CommonLib.jar
); the classnames are UserDatabase
and UserDatabaseEntityManager
and their definitions are as below (in the PS at the end of this message).
I also have an EAR with an EJB3.1 module in it.
When I choose to deploy the CommonLib.jar
as a "Bundled Library" of the EAR, then I get the following error:
Error occurred during deployment: Exception while loading the app : WELD-001408
Unsatisfied dependencies for type [EntityManager
] with qualifiers [@UserDatabase
] at injection point [[field] @UserDatabase @Inject com.test.TestEJB.itemPersistenceEm
]. Please see server.log
for more details.
Same error as above I get also when I deploy the CommonLib.jar as a shared library (jar file copied under $glasshfish_installation_path/domains/domain1/lib
)
BUT, if I choose to just have the two classes (UserDatabase
and UserDatabaseEntityManager
) in the EJB project (thus they are compiled within the EJB module), then the injection works fine.
Am I facing a classloader issue? Any ideas how I can get past this issue?
发布评论
评论(2)
只是一个猜测,因为几天前我在 Glassfish 和 CDI 中遇到了一个非常相似的问题:Do you have a
beans.xml
in every JAR,即在CommonLib.jar
和 EJB JAR,以便 CDI 扫描它们?我的问题是由于我认为将
beans.xml
放入 EAR 中就足够了,但事实并非如此。Just a guess, because I faced a very similar problem with Glassfish and CDI a few days ago: Do you have a
beans.xml
in every JAR, i.e. in theCommonLib.jar
and the EJB JAR, so that CDI scans both of them?My problem resulted from the fact that I thought placing a
beans.xml
into the EAR would be sufficient, which is not the case.听起来您好像遇到了我们在处理 Seam 3 时发现的一些 Glassfish CDI 集成问题。可能是其中几个,因此您必须看一下可能是哪一个。尝试在 JBoss AS7 或 Apache TomEE 上进行测试,看看是否仍然存在问题。
Sounds like you're running into some of the Glassfish CDI integration issues we've found while working on Seam 3. It could be a couple of them, so you'll have to take a look at see which one it may be. Try testing on JBoss AS7 or Apache TomEE and see if you still have problems.