我正在开发一个DAL jar库,但是我遇到了部署数据源XML文件的问题。
这是我的persistence.xml
文件,它位于DAL jar文件夹的META-INF
文件夹中
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="DALPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/myDS</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit>
</persistence>
这是数据源文件myDS-ds.xml
。它位于DAL库的同一META-INF
文件夹
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<xa-datasource jndi-name="java:jboss/datasources/myDS" pool-name="myDS"
enabled="true" jta="true" use-java-context="true" use-ccm="false">
<driver>com.mysql.jdbc.Driver</driver>
<xa-datasource-property name="URL">jdbc:mysql://localhost:3306/mydb</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<xa-pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>60</max-pool-size>
<prefill>true</prefill>
</xa-pool>
<security>
<user-name>user</user-name>
<password>pwd</password>
</security>
<validation>
<valid-connection-checker
class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter
class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"></exception-sorter>
</validation>
</xa-datasource>
</datasources>
然后我将这个jar库(作为Maven依赖项)包含在我在Wildfly 8.0.0应用程序服务器上运行的Web应用程序中。
问题在于,当我运行服务器并部署Web应用程序时,我得到以下日志堆栈
20:20:22,673 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
20:20:22,941 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final
20:20:23,032 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting
20:20:24,023 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
20:20:24,051 INFO [org.xnio] (MSC service thread 1-5) XNIO version 3.2.0.Final
20:20:24,058 INFO [org.xnio.nio] (MSC service thread 1-5) XNIO NIO Implementation Version 3.2.0.Final
20:20:24,092 INFO [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
20:20:24,099 INFO [org.jboss.as.security] (MSC service thread 1-1) JBAS013170: Current PicketBox version=4.0.20.Final
20:20:24,116 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
20:20:24,124 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
20:20:24,149 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]
20:20:24,170 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
20:20:24,181 INFO [org.jboss.as.connector.logging] (MSC service thread 1-4) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final)
20:20:24,189 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017502: Undertow 1.0.0.Final starting
20:20:24,190 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting
20:20:24,207 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
20:20:24,226 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) JBAS010417: Started Driver service with driver-name = h2
20:20:24,373 INFO [org.jboss.as.naming] (MSC service thread 1-3) JBAS011802: Starting Naming Service
20:20:24,375 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]
20:20:24,392 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 4.0.0.Final
20:20:24,548 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\wildfly-8.0.0.Final/welcome-content
20:20:24,576 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017525: Started server default-server.
20:20:24,595 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017531: Host default-host starting
20:20:24,751 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) JBAS015012: Started FileSystemDeploymentService for directory C:\wildfly-8.0.0.Final\standalone\deployments
20:20:25,074 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
20:20:25,180 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
20:20:25,345 INFO [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
20:20:25,434 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://0.0.0.0:9990/management
20:20:25,434 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://0.0.0.0:9990
20:20:25,434 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final "WildFly" started in 3050ms - Started 183 of 232 services (80 services are lazy, passive or on-demand)
20:20:34,799 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "testdal.war" (runtime-name: "testdal.war")
20:20:38,238 INFO [org.jboss.as.jpa] (MSC service thread 1-7) JBAS011401: Read persistence.xml for DALPersistenceUnit
20:20:38,430 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "testdal.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"testdal.war#DALPersistenceUnit\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.myDS]"]}
20:20:38,473 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "testdal.war" (runtime-name : "testdal.war")
20:20:38,474 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.jboss.datasources.myDS (missing) dependents: [service jboss.persistenceunit."testdal.war#DALPersistenceUnit".__FIRST_PHASE__]
正如您在行中看到ERROR
消息一样,Wildfly似乎无法在已部署的war存档中找到myDS-ds.xml文件。
您认为问题是什么?
谢谢
答案 0 :(得分:0)
您需要将myDS-ds.xml
直接部署到standalone/deployments
,服务器将注册此数据源。但是,最简单(也是推荐的方法)是将JDBC驱动程序部署到服务器,而不是通过管理控制台或CLI配置数据源(实际上不建议直接编辑XML配置文件,因此更容易出错)。另请参阅JBoss中有关WildFly的this教程。
答案 1 :(得分:0)
我解决了写一个用@DataSource注释注释的类。这样,数据源定义始终在应用程序容器中复制。