简体   繁体   中英

Deploy JBoss datasource in a jar library

I'm developing a DAL jar library but I'm having problems with the deployment of the datasources XML file.

Here is my persistence.xml file which is located in the META-INF folder of the DAL's jar library

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

And here is the datasource file myDS-ds.xml . It's located in the same META-INF folder of the DAL library

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

Then I included this jar library (as a Maven dependency) in a web application which I run on a Wildfly 8.0.0 application server.

The problem is that when I run the server and deploy the web app I get the following log stack

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__] 

As you can see at the row with a ERROR message, it seems that Wildfly cannot find the myDS-ds.xml file in the deployed war archive.

What do you think the problem can be?

Thank you

You need to deploy myDS-ds.xml directly to the standalone/deployments , server will register this datasource. However, the simplest (and recommended way) is to just deploy JDBC driver to the server and than configure the datasource via Management Console or CLI (it's not really recommended to directly edit XML configuration files, it's more error prone). See also this tutorial about WildFly from JBoss.

I solved writing a class annotated with the @DataSource annotation. This way the data source definition is always replicated in the application container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM