0

我正在构建一个基于Wildfly原型的 JavaEE 8 应用程序ord.wildfly.archetype:wildfly-jakarta-ear-archetype:23.0.0.Final并将其部署在Wildfly 23.0.2.Final.

这将创建 4 个项目

test
|---test-ear
|---test-ejb
|---test-web

其中test-war将依赖项声明test-ejb为提供的模块。

但是,如果我这样定义@Singleton @StartupEJBtest-ejb

@Singleton
@Startup
public class Bootstrap {
    
    @PostConstruct
    public void postContruct() {
        System.out.println("********* BOOTSTRAP *********");
    }
    
}

它被初始化两次:一次test-ejb是在部署时,另一次test-web是在部署时。

@Singleton考虑到依赖项的定义和provided范围,我没想到会这样。

我没有在项目配置中做任何事情,我只是添加了如上所述的单例类(我什至没有声明对记录器库的任何依赖,以将我的修改保持在最低限度)

我究竟做错了什么?


更新:添加清单和描述符

测试网

清单文件

Manifest-Version: 1.0
Build-Jdk-Spec: 15
Created-By: Maven Integration for Eclipse

豆类.xml

<?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

<?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>

更新:日志

深入研究日志,看起来问题实际上是双重部署而不是依赖问题。

在部署期间(通过 Eclipse),我看到第一块内容如下:

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

EJB 和 WAR 模块被处理两次是否正确?


更新:野蝇日志

刚刚尝试增加 Wildfly 本身的日志级别。浏览生成的文件,我没有看到任何异常。但我注意到了这一点:

2021-06-22 18:44:59,357 DEBUG [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) Deployment scan of [/home/xxxx/wildfly-23.0.2.Final/standalone/deployments] found update action [{
    "operation" => "composite",
    "address" => [],
    "steps" => [
        {
            "operation" => "add",
            "address" => [("deployment" => "togather-engine.ear")],
            "content" => [{
                "archive" => false,
                "path" => "deployments/XXXX.ear",
                "relative-to" => "jboss.server.base.dir"
            }],
            "persistent" => false,
            "owner" => [
                ("subsystem" => "deployment-scanner"),
                ("scanner" => "default")
            ]
        },
        {
            "operation" => "deploy",
            "address" => [("deployment" => "XXXX.ear")],
            "owner" => [
                ("subsystem" => "deployment-scanner"),
                ("scanner" => "default")
            ]
        }
    ],
    "operation-headers" => {"rollback-on-runtime-failure" => false}
}]

过了一会儿

2021-06-22 18:45:11,886 DEBUG [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) Deployment scan of [/home/xxxxx/wildfly-23.0.2.Final/standalone/deployments] found update action [{
    "operation" => "redeploy",
    "address" => [("deployment" => "XXXX.ear")],
    "owner" => [
        ("subsystem" => "deployment-scanner"),
        ("scanner" => "default")
    ]
}]

我在 Wildfly 23 和 22 上验证了相同的行为。

4

0 回答 0