首页 > 解决方案 > WELD-001408 对 EJB 项目的依赖不满足

问题描述

我有一个包含三个项目的多模块 Maven 项目。第一个具有共享数据的 ejb 项目test-base。第二个 ejb 项目test-timer应部署在 glassfish 4.x 应用程序服务器上以运行定期任务 ( @Scheduel) 并依赖于test-base. 最后是第三个带有简单 webapp 的战争项目test-webapp,它也依赖于test-base并且也将单独部署到 glassfish 4.x 应用程序服务器。在test-base项目中是一个 CDI bean。该项目包含 beans.xml。

test-webapp奇迹般有效。但是,如果我尝试部署,则会test-timer出现部署异常。

org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [MyCdiBean] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private org.test.MyTimer.bean]

在网上搜索后(即此处此处),我认为它与beans.xml. test-base包含一个beans.xml并且 webapp 运行得很好。与test-timer我是否有beans.xml没有关系一样。

beans.xml由 netbeans ide 生成,如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

我也试图改变bean-discovery-mode="all"两者test-basetest-timer但没有任何改变。

这是我的项目结构。

test-parent
|--test-base
   |--src
      |--main
         |--java
            |--org/test/MyCdiBean.java
         |--resources
            |--META-INF
               |--beans.xml
      |--test
   |--pom.xml
|--test-timer
   |--src
      |--main
         |--java
            |--org/test/MyTimer.java
         |--resources
            |--META-INF
               |--beans.xml
      |--test
   |--pom.xml
|--test-webapp
   |--src
      |--main
         |--java
            |--org/test/WebAppBean.java
         |--resources
            |--META-INF
               |--beans.xml
         |--webapp
            |--WEB-INF
               |--web.xml
            |--index.xhtml
      |--test
   |--pom.xml
|--pom.xml

感谢任何关于我做错了什么的提示。

如有必要,我可以附上来源。

编辑评论中要求的附加信息。

现在是新beans.xml的。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
   bean-discovery-mode="annotated">
</beans>

仍然不起作用。

我正在使用 WELD 版本WELD-000900 2.0.0 (SP1),并使用它进行了测试WELD-000900: 2.2.13 (Final)

MyCdiBean.java 在test-base

@javax.inject.Named 
@javax.enterprise.context.RequestScoped 
//@javax.enterprise.context.Dependent /* also tried with  */
public class MyCdiBean {
    public void doSomething() {
        System.out.println("Hello World!");
    }
}

标签: mavenjakarta-eecdiglassfish-4weld

解决方案


推荐阅读