使用本地数据源而不是在standalone.xml中指定它(WildFly)

时间:2017-10-17 15:17:11

标签: java-ee deployment jboss datasource wildfly

我通常在standalone.xml中列出我的数据源(只是一个示例):

<datasource jta="false" jndi-name="java:jboss/datasources/myDB" pool-name="myDB" enabled="true" use-ccm="false">
    <connection-url>jdbc:mysql://mysql/myDB</connection-url>
    <driver>mysql</driver>
    <security>
        <user-name>root</user-name>
        <password>password</password>
    </security>
    <validation>
        <validate-on-match>false</validate-on-match>
        <background-validation>false</background-validation>
    </validation>
    <statement>
        <share-prepared-statements>false</share-prepared-statements>
    </statement>
</datasource>

MySQL驱动程序已安装到WildFly。我知道可以将数据源添加到webapp --> WEB-INF --> my-ds.xml

但是当我将我的建筑战争部署到WildFly时,我得到了

16:59:15,121 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "poc")]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.data-source.\"jboss.naming.context.java.jboss.datasources.testDB\" is missing [jboss.jdbc-driver.mysql]"]
}
16:59:15,124 ERROR [org.jboss.as.server] (management-handler-thread - 3) WFLYSRV0021: Deploy of deployment "poc.war" was rolled back with the following failure message: 
{
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.data-source.\"jboss.naming.context.java.jboss.datasources.testDB\" is missing [jboss.jdbc-driver.mysql]"]
}

我的问题是:

如何将我的数据源定义从standalone.xml移动到我的项目,并在部署到WildFly时使其工作

2 个答案:

答案 0 :(得分:0)

已经想出如何解决问题。

首先添加boss-deployment-structure.xml(到WEB-INF f.e。),其中必须指定驱动程序:

<?xml version="1.0"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="com.mysql" services="export">
                <imports>
                    <include path="META-INF**"/>
                    <include path="com**"/>
                    <!-- assuming user of the driver is com.something -->
                </imports>
            </module>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

然后我按-ds.xml模式添加我的数据源。 (WildFly 10实际上已经弃用了......)

在我的persistence.xml我现在可以使用数据源了。

答案 1 :(得分:-1)

您可以将其放在deployments目录中,而不是在应用程序中放置数据源-ds.xml。