1.MySQL Connector/J 다운로드
다운로드 경로 : https://dev.mysql.com/downloads/connector/
commands 사용 : $ wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.17.tar.gz
2. 압축 해제 후 Wildfly Module에 MySQL JDBC Driver 설치
압축을 풀어 mysql-connector-java-8.0.17.jar 를
(com/mysql/main) 폴더를 생성하여 main폴더안에 넣습니다.
$ mkdir -p WILDFLY_HOME/modules/system/layers/base/com/mysql/main
그리고 jar파일이 있는 폴더에 module.xml을 생성합니다.
$ vim module.xml
해당 내용을 복사하여 붙여넣습니다.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-8.0.17.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<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/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://[ip]:[port[/[sid]?characterEncoding=euc_kr&serverTimezone=UTC</connection-url>
<driver>mysql</driver>
<security>
<user-name>id</user-name>
<password>passwd</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
<drivers>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
4. 확인방법
WILDFLY 관리자화면 webconsole 화면 기본포트:9990
Test Connection 을 클릭하여 Successfully가 나오면 성공이다.
commands 사용 : cli에 접속하여 커넥션 테스트를 해보면됨
5. 주의사항
– 에러 유형 –
1. The server time zone value ‘KST’ is unrecognized or represents more than one time zone : mysql-connector-java 버전 5.1.X 이후 버전부터 KST 타임존을 인식하지 못하는 이슈
jdbc:mysql://ip:port/TestDB?characterEncoding=UTF-8&serverTimezone=UTC
2. JDBC-Driver 클래스 지정을 com.mysql.jdbc.Driver 으로 한 경우
mysql-connector-java 버전 6.xx 이상이 되면 JDBC-Driver 클래스를 com.mysql.cj.jdbc.Driver 로 해야한다.
3. JDBC 클래스 XA 이슈
(failure description: "WFLYJCA0114: Failed to load datasource class: com.mysql.jdbc.Driver")
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
혹은
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
이렇게 설정 정확한 JDBC XA Driver를 적어줘야합니다.