使用本地数据源,而不是在standalone.xml(WildFly)
问题描述:
我通常在standalone.xml上市一样(只是一个样本)我的数据源指定它:使用本地数据源,而不是在standalone.xml(WildFly)
<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
但是当我部署我buildet战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时工作
答
已经想出了如何解决这个问题。
首先是添加boss-deployment-structure.xml
(以WEB-INF
远东),其中一个具有指定驱动程序:
<?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
我现在可以使用数据源。
答
而不是将数据源,-ds.xml放在应用程序中,您可以将它放在部署目录中。
你是如何安装mysql驱动程序的? –
它作为一个模块安装,我已经解决了这个问题 – x4k3p
你有吗? WildFly配置中驱动程序的名称是什么?请运行jboss-cli.sh并将'ls subsystem = datasources'的输出添加到您的问题中,因为您似乎没有名为'mysql'的驱动程序。 –