記錄WildFly 14 增加MySQL 8.0.11 數(shù)據(jù)源的過程,希望對(duì)大家有所幫助。
1、下載MySQL 8.0驅(qū)動(dòng)jar包
mysql-connector-java-8.0.11.jar
具體下載見本文最后的Linux公社資源站。
2、增加mysql能動(dòng)module
a>在/usr/local/wildfly14/modules/system/layers/base/com目錄并拷貝mysql驅(qū)動(dòng)
$mkdir -p mysql/main
$cd mysql/main
$cp ~/mysql-connector-java-8.0.11.jar ./
$vim module.xml
b>增加module.xml內(nèi)容如下
<?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驅(qū)動(dòng)模塊增加完成。
3、在配置文件中增加數(shù)據(jù)源
a>進(jìn)入/usr/local/wildfly14/standalone/configuration目錄
b>打開standalone.xml配置文件
c>找到drivers標(biāo)簽,并且增加如下driver
<drivers>
<driver name=”h2″ module=”com.h2database.h2″>
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<!– 增加下面mysql驅(qū)動(dòng) –>
<driver name=”mysql” module=”com.mysql”>
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
d>找到datasources標(biāo)簽,并且增加如下datasource
<datasource jndi-name=”java:jboss/datasources/LotteryDS” pool-name=”LotteryDS” enabled=”true” use-java-context=”true”>
<connection-url>jdbc:mysql://localhost:3306/數(shù)據(jù)庫名?useSSL=false&connectionCollation=utf8_general_ci&characterSetResults=utf8&characterEncoding=utf8</connection-url>
<driver>mysql</driver>
<security>
<user-name>數(shù)據(jù)庫用戶名</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的話,啟動(dòng)wildfly應(yīng)該會(huì)報(bào)一個(gè)錯(cuò)誤
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數(shù)據(jù)源,在web管理界面就可以看到多了一個(gè)jdbc驅(qū)動(dòng)和一下數(shù)據(jù)源,如下圖
本文相關(guān)附件mysql-connector-java-8.0.11.jar可以到Linux公社資源站下載:
——————————————分割線——————————————
免費(fèi)下載地址在 http://linux.linuxidc.com/
用戶名與密碼都是www.linuxidc.com
具體下載目錄在 /2018年資料/9月/28日/WildFly 14 增加MySQL 8.0.11 數(shù)據(jù)源/
下載方法見 http://www.linuxidc.com/Linux/2013-07/87684.htm
——————————————分割線——————————————