记录WildFly 14 增加MySQL 8.0.11 数据源的过程,希望对大家有所帮助。
1、下载MySQL 8.0驱动jar包
mysql-connector-Java-8.0.11.jar
具体下载见本文最后的Linux公社资源站。
2、增加mysql能动module
a>在/usr/local/wildfly14/modules/system/layers/base/com目录并拷贝mysql驱动
$mkdir -p mysql/main $cd mysql/main $cp ~/mysql-connector-java-8.0.11.jar ./ $vim module.xml
b>增加module.xml内容如下
<?xml version="1.0" encoding="UTF-8"?>
<module name="com.mysql" xmlns="urn:jboss:module:1.5">
<resources> <resource-root path="mysql-connector-java-8.0.11.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> <module name="javax.servlet.api" optional="true"/> </dependencies> </module>
至此mysql驱动模块增加完成。
3、在配置文件中增加数据源
a>进入/usr/local/wildfly14/standalone/configuration目录
b>打开standalone.xml配置文件
c>找到drivers标签,并且增加如下driver
<drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> <!-- 增加下面mysql驱动 --> <driver name="mysql" module="com.mysql"> <xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class> </driver> </drivers>
d>找到datasources标签,并且增加如下datasource
<datasource jndi-name="java:jboss/datasources/LotteryDS" pool-name="LotteryDS" enabled="true" use-java-context="true"> <connection-url>jdbc:mysql://localhost:3306/数据库名?useSSL=false&connectionCollation=utf8_general_ci&characterSetResults=utf8&characterEncoding=utf8</connection-url> <driver>mysql</driver> <security> <user-name>数据库用户名</user-name> <password>密码</password> </security>
<validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/> <background-validation>true</background-validation> <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/> </validation> </datasource>
特别注意:
如果connection-url没有增加useSSL=false的话,启动wildfly应该会报一个错误
Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45 , 5.6.26 and 5.7.6 requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
至此就增加好了mysql数据源,在web管理界面就可以看到多了一个jdbc驱动和一下数据源,如下图
本文相关附件mysql-connector-java-8.0.11.jar可以到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2018年资料/9月/28日/WildFly 14 增加MySQL 8.0.11 数据源/
下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm
------------------------------------------分割线------------------------------------------