Jakarta ee Wildfly JavaEE 8-单例EJB的双重初始化
我正在基于Jakarta ee Wildfly JavaEE 8-单例EJB的双重初始化,jakarta-ee,wildfly,ejb-3.2,Jakarta Ee,Wildfly,Ejb 3.2,我正在基于Wildflyarchetypeord.Wildfly.archetype:Wildfly-jakarta-ear-archetype:23.0.0.Final构建一个JavaEE8应用程序,并将其部署在Wildfly 23.0.2.Final上 这将创建4个项目 test |---test-ear |---test-ejb |---test-web 其中,testwar声明对testejb的依赖关系作为提供的模块 但是,如果我在testejb中定义@Singleton@Startu
Wildfly
archetypeord.Wildfly.archetype:Wildfly-jakarta-ear-archetype:23.0.0.Final
构建一个JavaEE8应用程序,并将其部署在Wildfly 23.0.2.Final
上
这将创建4个项目
test
|---test-ear
|---test-ejb
|---test-web
其中,testwar
声明对testejb
的依赖关系作为提供的模块
但是,如果我在testejb
中定义@Singleton@Startup
EJB,就像这样
@Singleton
@Startup
public class Bootstrap {
@PostConstruct
public void postContruct() {
System.out.println("********* BOOTSTRAP *********");
}
}
它被初始化两次:一次是在部署测试ejb
时,另一次是在部署测试web
时
考虑到@Singleton
的定义和提供的依赖范围,我没想到会出现这种情况
我没有在项目配置中做任何事情,只是如上所述添加了singleton类(我甚至没有声明对logger LIB的任何依赖,以将修改保持在最低限度)
我做错了什么
更新:添加清单和描述符
测试网
MANIFEST.MF
beans.xml
application.xml
然后,我看到第二块:
...
18:13:48,243 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment test.ear
18:13:48,265 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment test-web.war
18:13:48,268 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment test-ejb.jar
...
18:13:48,507 INFO [stdout] (ServerService Thread Pool -- 87) ********* BOOTSTRAP *********
18:13:48,507 INFO [stdout] (ServerService Thread Pool -- 87) ********* POST CONSTRUCT com.test.test.Bootstrap@1606409c *********
...
EJB和WAR模块被处理两次是否正确?就像第一次健全性测试一样,如果test-EJB.jar以某种方式结束,您是否检查了test-WAR/WEB-INF/lib的内容?另一个健全性检查是war的MANIFEST.MF,它是否声明了对测试ejb的依赖关系?哦,还请检查战争中jboss特定的部署描述符(如果有的话)(也可能是ear,我不记得那里是否有干扰)@NikosParaskevopoulos您好,我已经将我可以找到的资源添加到原始帖子中。它们没有被修改,它们绝对是由开箱即用的原型创建的。@NikosParaskevopoulos我还做了一个测试,看看Bootstrap类是否被设置了两次,或者只是调用了两次后构造方法:结果是第一个选项是正确的:启动类被重新启动两次,因此每个实例的后构造方法都被调用。嗨,您是否检查了部署的war的WEB-INF/lib,以防ejb jar在其中找到它?@NikosParaskevopoulos-hi。不,部署的WAR库中没有任何内容(实际上,由于WAR上没有明确声明的依赖项(仅提供或测试),因此根本没有库文件夹)
<?xml version="1.0" encoding="UTF-8"?>
<beans version="2.0"
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_2_0.xsd"
bean-discovery-mode="annotated">
<!-- This descriptor configures Context and Dependeny Injection.
Actually, CDI 1.1 does not require this file. But the archetype contains it anyway to avoid deloyment errors for blank projects (WFLY-13306) -->
</beans>
Manifest-Version: 1.0
Build-Jdk-Spec: 15
Created-By: Maven Integration for Eclipse
<?xml version="1.0" encoding="UTF-8"?>
<application 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/application_8.xsd" version="8">
<description>This is the EAR POM file</description>
<display-name>test-ear</display-name>
<module>
<ejb>test-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>test-web.war</web-uri>
<context-root>/test-web</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
...
18:52:15,803 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment test.ear
18:52:15,852 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-7) HV000001: Hibernate Validator 6.0.22.Final
18:13:46,577 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment test-web.war
18:13:46,585 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment test-ejb.jar
...
18:13:47,754 INFO [stdout] (ServerService Thread Pool -- 87) ********* BOOTSTRAP *********
18:13:47,757 INFO [stdout] (ServerService Thread Pool -- 87) ********* POST CONSTRUCT com.test.test.Bootstrap@65495f *********
...
...
18:13:48,243 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment test.ear
18:13:48,265 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment test-web.war
18:13:48,268 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment test-ejb.jar
...
18:13:48,507 INFO [stdout] (ServerService Thread Pool -- 87) ********* BOOTSTRAP *********
18:13:48,507 INFO [stdout] (ServerService Thread Pool -- 87) ********* POST CONSTRUCT com.test.test.Bootstrap@1606409c *********
...