我正在使用Wildfly 10.起初我尝试通过CLI创建数据源.
命令部署mysql-connector-java-6.0.4.jar执行得很好.
/ subsystem = datasources:installed-drivers-list显示已安装驱动程序
{
"driver-name" => "mysql-connector-java-6.0.4.jar",
"deployment-name" => "mysql-connector-java-6.0.4.jar",
"driver-module-name" => undefined,
"module-slot" => undefined,
"driver-datasource-class-name" => undefined,
"driver-xa-datasource-class-name" => undefined,
"driver-class-name" => "com.mysql.cj.jdbc.Driver",
"driver-major-version" => 6,
"driver-minor-version" => 0,
"jdbc-compliant" => false
}
但数据源不是使用命令创建的
data-source add --name=zktest-datasource
--jndi-name=java:/jdbc/zktest-database --driver-name=mysql-connector-java-6.0.4.jar --connection-url=jdbc:mysql://localhost:3306/zktest --user-name=root --password=111
连接测试
/subsystem=datasources/data-source=zktest-datasource:test-connection-in-pool
was failed.
现在我尝试使用standalone.xml创建数据源
我的modules.xml
<module xmlns="urn:jboss:module:1.1" name="com.mysql.jdbc">
<resources>
<resource-root path="mysql-connector-java-6.0.4.jar">
</resource-root>
</resources>
<dependencies>
<module name="javax.api"></module>
<module name="javax.transaction.api"></module>
</dependencies>
</module>
modules.xml放在JBOSS_HOME / modules / system / layers / base / com / mysql / jdbc中
JBOSS_HOME / standalone / configuration / standalone.xml中的“Datasources”部分
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/zktest</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>111</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.cj.jdbc.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
现在,虽然deploing我看到这样的消息
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.driver-demander.java:jboss/datasources/MySqlDS, service
org.wildfly.data-source.MySqlDS]
在Wildfly控制面板中进行测试连接时:
{
“outcome” => “failed”,
“failure-description” => “WFLYJCA0040: failed to invoke operation: WFLYJCA0042: failed to match pool. Check JndiName:
java:jboss/datasources/MySqlDS”,
“rolled-back” => true }
解决方法:
通过将驱动程序更改为mysql-connector-java-5.1.38.jar解决了问题.
我删除了旧驱动程序,然后在CLI中执行了以下步骤:
module add --name=com.mysql.jdbc --resources=mysql-connector-java-5.1.38.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=mysql:add(driver-name="mysql",driver-module-name="com.mysql.jdbc",driver-class-name=com.mysql.jdbc.Driver)
data-source add --name=MySQLDS --driver-name=mysql --connection-url=jdbc:mysql://localhost:3306/zktest --jndi-name=java:jboss/jdbc/MySQLDS --user-name=username --password=password
data-source enable --name=MySQLDS