Wildfly 部署因缺少数据源而失败

Wildfly deploy fail for missing datasource

我正在尝试部署 SPECjEnterprise®2018 Web 配置文件来对 WildFly 进行基准测试。基准文档没有指定任何部署指令,说它超出了文档的范围。

我尝试部署 .war 文件,但出现以下错误:

00:39:12,410 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "insurance.war")]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jdbc.SPECjInsuranceDS"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.persistenceunit.\"insurance.war#InsuranceAudit\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.SPECjInsuranceDS]",
        "jboss.persistenceunit.\"insurance.war#InsuranceAudit\" is missing [jboss.naming.context.java.jdbc.SPECjInsuranceDS]",
        "jboss.persistenceunit.\"insurance.war#Insurance\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.SPECjInsuranceDS]",
        "jboss.persistenceunit.\"insurance.war#Insurance\" is missing [jboss.naming.context.java.jdbc.SPECjInsuranceDS]"
    ]
}

这是我正在尝试部署的 .warpersistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
   xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="Insurance">
       <jta-data-source>jdbc/SPECjInsuranceDS</jta-data-source>
       <class>org.spec.jent.common.Address</class>
       <class>org.spec.jent.common.insurance.entity.PolicyCoverage</class>
       <class>org.spec.jent.common.insurance.entity.PolicyHolder</class>
       <class>org.spec.jent.common.SPECjWebTarget</class>
       <class>org.spec.jent.common.insurance.entity.Vehicle</class>
       <class>org.spec.jent.common.insurance.entity.VehicleInsurance</class>
       <!--  class>org.spec.jent.vehicle.entity.VehicleDescription</class -->
       <shared-cache-mode>NONE</shared-cache-mode>
   </persistence-unit>
</persistence>

还有standalone.xml中定义的数据源:

            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/jdbc/SPECjInsuranceDS" pool-name="SPECjInsuranceDS">
                    <connection-url>jdbc:postgresql://localhost:5432/specdb</connection-url>
                    <driver>postgres</driver>
                    <security>
                        <user-name>specdb</user-name>
                        <password>root</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name="postgres" module="org.postgres">
                        <driver-class>org.postgresql.Driver</driver-class>
                    </driver>
                </drivers>
            </datasources>

如您所见,我添加了所需的数据源,并在 Wildfly 控制台中测试了连接。

提前感谢您的回复。

正确的 jndi-namejndi-name="java:/jdbc/SPECjInsuranceDS" 而不是 jndi-name="java:jboss/datasources/jdbc/SPECjInsuranceDS"

那么更新后的standalone.xml就是:

<datasources>
   <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
      <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
      <driver>h2</driver>
      <security>
         <user-name>sa</user-name>
         <password>sa</password>
      </security>
   </datasource>
   <datasource jndi-name="java:jboss/datasources/jdbc/SPECjInsuranceDS" pool-name="SPECjInsuranceDS">
      <connection-url>jdbc:postgresql://localhost:5432/specdb</connection-url>
      <driver>postgres</driver>
      <security>
         <user-name>specdb</user-name>
         <password>root</password>
      </security>
   </datasource>
   <drivers>
      <driver name="h2" module="com.h2database.h2">
         <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
      </driver>
      <driver name="postgres" module="org.postgres">
         <driver-class>org.postgresql.Driver</driver-class>
      </driver>
   </drivers>
</datasources>