除非明确注释,否则不会发现 CDI bean
CDI bean doesn’t get discovered unless explicitly annotated
当 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 存档是默认的,这意味着 class 只有当它有像 @Dependent
这样的 bean 定义注释时才是候选 bean, @RequestScoped
等
当 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 存档是默认的,这意味着 class 只有当它有像 @Dependent
这样的 bean 定义注释时才是候选 bean, @RequestScoped
等