我有一个JAVA EE 7项目,它使用WildFly 9.0.2最终版本作为应用程序服务器,我使用web.xml上的标记配置了数据源,它工作正常,但是当我使用WildFly 8.1时它不再起作用了
web.xml的相关部分:
<!-- Mysql datasource configuration -->
<data-source>
<name>java:app/datasources/MysqlAuronDS</name>
<class-name>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</class-name>
<url>jdbc:mysql://localhost:3306/auron</url>
<user>root</user>
<password>123456</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
<initial-pool-size>2</initial-pool-size>
<max-pool-size>100</max-pool-size>
<min-pool-size>10</min-pool-size>
<max-statements>0</max-statements>
</data-source>
<!-- Postgres datasource configuration -->
<data-source>
<name>java:app/datasources/PostgresAuronDS</name>
<class-name>org.postgresql.xa.PGXADataSource</class-name>
<url>jdbc:postgresql://localhost:5432/auron</url>
<user>postgres</user>
<password>123456</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
<initial-pool-size>2</initial-pool-size>
<max-pool-size>100</max-pool-size>
<min-pool-size>10</min-pool-size>
<max-statements>0</max-statements>
</data-source>
persistence.xml上的持久性单元:
<persistence-unit name="" transaction-type="JTA">
<description>Forge Persistence Unit</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:app/datasources/PostgresAuronDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.transaction.flush_before_completion"
value="true" />
<!--
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
-->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
日志是:
18:34:31,251 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "auron.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"auron.war#\".__FIRST_PHASE__ is missing [jboss.naming.context.java.app.auron.datasources.PostgresAuronDS]"]}
18:34:31,314 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "auron.war" (runtime-name : "auron.war")
18:34:31,320 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.app.auron.datasources.PostgresAuronDS (missing) dependents: [service jboss.persistenceunit."auron.war#".__FIRST_PHASE__]
18:34:31,558 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment auron.war (runtime-name: auron.war) in 18ms
18:34:31,605 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
18:34:31,605 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
18:34:31,606 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 6119ms - Started 184 of 233 services (81 services are lazy, passive or on-demand)
18:34:31,817 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "auron.war" (runtime-name: "auron.war")
18:34:31,818 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.persistenceunit."auron.war#".__FIRST_PHASE__ (missing) dependents: [service jboss.deployment.unit."auron.war".POST_MODULE]
请注意,我已经配置了两个数据源,我可以更改持久性单元上的数据源,还要注意所需的驱动程序由maven处理。