簡體   English   中英

在jar庫中部署JBoss數據源

[英]Deploy JBoss datasource in a jar library

我正在開發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文件。

您認為問題可能是什么?

謝謝

您需要將myDS-ds.xml直接standalone/deploymentsstandalone/deployments服務器standalone/deployments ,服務器將注冊此數據源。 但是,最簡單(也是推薦的方法)是僅將JDBC驅動程序部署到服務器上,而不是通過管理控制台或CLI配置數據源(不建議直接編輯XML配置文件,因為它更容易出錯)。 另請參見教程的WildFly從JBoss的。

我解決了編寫帶有@DataSource批注的類的問題。 這樣,數據源定義總是復制到應用程序容器中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM