SRy*_*SRy 4 java cdi jsf-2 ejb-3.1 jboss-weld
我正在使用weld
,CDI的RI作为我的JSF-EJB-JPA Web应用程序中的依赖注入组件.我在我的项目看,我们有空的beans.xml在 META-INF/beans.xml
中ejb.jar
和WEB-INF/beans.xml
在我的抗战.我不明白为什么我们需要beans.xml
在那个文件中没有定义时保持空?
完全空的情况与存档内部包含以下内容beans.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="all">
</beans>
Run Code Online (Sandbox Code Playgroud)
由于bean-discovery-mode="all",将扫描存档中的 beans。无需注释它们。
不存在它与存档内有以下内容beans.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>
Run Code Online (Sandbox Code Playgroud)
由于bean-discovery-mode="annotated",将在存档中扫描带注释的类中的 bean(例如@Dependent
)。所有其他类将被忽略,因此不能作为 bean 注入。
第三个选项是声明bean-discovery-mode="none"在这种情况下,服务器永远不会扫描存档中的 Bean。
现在,对于您想要将类作为 bean 加载但无法访问存档(例如外部库)并且该类没有注释的情况,解决方案是使用 Producer方法(带或不带限定符)。
归档时间: |
|
查看次数: |
2279 次 |
最近记录: |