![](/img/trans.png)
[英]Java EE CDI Deployment Exception - WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default
[英]CDI can not inject pojo java class. (Unsatisfied dependencies for type Pojo with qualifiers @Default)
嗨,我在将常规 Java 类(Pojo 类)注入 EJB bean 时遇到问题。
@ApplicationScoped
public class DomainRouteFinderService {
@Inject
private Pojo pojo;
private AtomicInteger sequencer;
@PostConstruct
private void init(){
sequencer = new AtomicInteger();
sequencer.lazySet(0);
}
@Produces
@Named("sequencer")
public String getText(){
return "Number: "+ sequencer.getAndIncrement();
}
}
Pojo类:
public class Pojo {
}
在我的多项目中,结构如下:
根 - 耳朵
Web 模块依赖于 ejb。
在 web 模块中是 beans.xml 和 bean-discovery-mode="all"
我通过向 ejb 添加另一个 beans.xml 解决了我的问题。 我把这个文件放到 main/java/resources/META-INF 本地化。
为什么?
CD 1.1/Java EE 7 中最重要的变化之一是,根据流行的要求,现在默认启用 CDI。 这意味着不再需要显式添加 beans.xml 来启用 DI。 但是,了解 CDI 现在还通过“bean-discovery-mode”属性对组件扫描提供更细粒度的控制也非常重要。 此属性具有三个可能的值:
'annotated' - loosely translated, means that only components with a class-level annotation are processed. 'all' - all components are processed, just like they were in Java EE 6 with the explicit beans.xml. 'none' - CDI is effectively disabled.
默认情况下,如果您不指定任何内容并且没有 beans.xml,则假定为 'annotated' 而不是 'all' 的 bean 发现模式。
但我想为 ejb 模块和 war 模块创建一个 beans.xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.