当 Weld 在 bean 是 POJO 时说“不满足类型 Foo 的依赖性”是什么意思,但是只要我在顶部添加 @Dependent
,一切正常?
我记得它曾经在不指定范围的情况下工作正常。我想我弄坏了什么。
规范说明:
A managed bean is implemented by a Java class, which is called its bean class. A top-level Java class is a managed bean if it is defined to be a managed bean by any other Java EE technology specification, such as the JavaServer Faces technology specification, or if it meets all the following conditions.
It is not a nonstatic inner class.
It is a concrete class or is annotated @Decorator.
It is not annotated with an EJB component-defining annotation or declared as an EJB bean class in ejb-jar.xml.
It has an appropriate constructor. That is, one of the following is the case.
The class has a constructor with no parameters.
The class declares a constructor annotated @Inject.
No special declaration, such as an annotation, is required to define a managed bean.
最佳答案
听起来您已经习惯了 CDI 1.0,现在对 CDI 1.1 中引入的隐式 bean 归档感到困惑。
beans.xml
现在是可选的,隐式 bean 存档是默认的,这意味着只有当一个类有一个像 @Dependent
这样的 bean 定义注释时,它才是一个 bean 候选者。 , @RequestScoped
等
关于java - 除非明确注释,否则不会发现 CDI bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534355/