简体   繁体   English

CDI 不能注入 pojo java 类。 (带有限定符 @Default 的 Pojo 类型的不满意依赖项)

[英]CDI can not inject pojo java class. (Unsatisfied dependencies for type Pojo with qualifiers @Default)

Hi i have a problem with inject a regular java class (Pojo class) into EJB bean.嗨,我在将常规 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 class: Pojo类:

public class Pojo {
}

In my multiprojects with structure like below:在我的多项目中,结构如下:

ROOT - ear根 - 耳朵

  1. ejb ejb
  2. web网络

Web module depends on ejb. Web 模块依赖于 ejb。

In web module is beans.xml with bean-discovery-mode="all"在 web 模块中是 beans.xml 和 bean-discovery-mode="all"

I resolved my problem by adding another beans.xml to ejb.我通过向 ejb 添加另一个 beans.xml 解决了我的问题。 I put this file to main/java/resources/META-INF localization.我把这个文件放到 main/java/resources/META-INF 本地化。

Why?为什么?

One of the most significant changes in CD 1.1/Java EE 7 is that by popular request, CDI is now enabled by default. CD 1.1/Java EE 7 中最重要的变化之一是,根据流行的要求,现在默认启用 CDI。 This means that there's no need to explicitly add a beans.xml to enable DI any more.这意味着不再需要显式添加 beans.xml 来启用 D​​I。 However, it is also very important to understand that CDI now also provides finer grained control over component scanning via the 'bean-discovery-mode' attribute.但是,了解 CDI 现在还通过“bean-discovery-mode”属性对组件扫描提供更细粒度的控制也非常重要。 This attribute has three possible values:此属性具有三个可能的值:

 '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.

By default, if you specify nothing and there is no beans.xml, the bean discovery mode of 'annotated' and not 'all' is assumed.默认情况下,如果您不指定任何内容并且没有 beans.xml,则假定为 'annotated' 而不是 'all' 的 bean 发现模式。

But i want to one beans.xml for ejb module and war module.但我想为 ejb 模块和 war 模块创建一个 beans.xml。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java EE CDI部署异常-WELD-001408:带有限定符@Default的EntityManager类型的依赖关系未满足 - Java EE CDI Deployment Exception - WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default 对类型[***的依赖性不满意 <T> ]在注入点[[field] @Inject处带有限定符[@Default] - Unsatisfied dependencies for type [***<T>] with qualifiers [@Default] at injection point [[field] @Inject 替代性CDI实施-WELD-001408:类型库的限定符@Default的不满意依赖性 - Alternative CDI implementation - WELD-001408: Unsatisfied dependencies for type Repository with qualifiers @Default 在注入点使用限定符 [@Default] 的类型 [...] 的不满意依赖项(使用带有 CDI 的 @Stateful EJB) - Unsatisfied dependencies for type […] with qualifiers [@Default] at injection point (using @Stateful EJB with CDI) 带有限定符 @Default 的类型 EntityManager 的不满意依赖项 - Unsatisfied dependencies for type EntityManager with qualifiers @Default 带有限定符[@Default]的[PartitionManager]类型的依赖关系未满足? - Unsatisfied dependencies for type [PartitionManager] with qualifiers [@Default]? 在注入点使用限定符 @default 的类型的依赖关系不满足 - Unsatisfied dependencies for type with qualifiers @default at injection point 带有限定符@Default的XXXX类型的Arquillian不满意的依赖项 - Arquillian Unsatisfied dependencies for type XXXX with qualifiers @Default ZZZZ类型与限定符@Default的不满意依赖关系 - Unsatisfied dependencies for type ZZZZ with qualifiers @Default WELD-001408:在注入点 [BackedAnnotatedField] @Inject 具有限定符 @Default 的类型 Logger 的依赖关系不满足 - WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default at injection point [BackedAnnotatedField] @Inject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM