配置WildFly的JDBC驱动一般有两种方式
(1) 以module的形式安装;
(2) 以deploy应用程序包的形式安装;
不过对于WildFly以domain模式运行而言,最好采用第一种module的方式,因为以应用程序包的形式安装的话,需要当前的WildFly服务器有server存在,而domain的模式,可以没有server存在(如作为domain controller存在),因此建议domain形式的服务器以module的形式安装。
1. 配置驱动
环境及软件包信息:
版本
环境
wildfly-10.1.0.Final
CentOS7 64bit
mysql-connector-java-5.1.35.jar
CentOS7 64bit
(1) module形式安装
1、下载好mysql的JDBC驱动,比如版本mysql-connector-java-5.1.35.jar;
2、进入$WILDFLY_HOME/modules/system/layers/base/com目录,创建目录mysql/main;
3、将mysql-connector-java-5.1.35.jar拷贝至$WILDFLY_HOME/modules/system/layers/base/com/mysql/main目录下;
4、在$WILDFLY_HOME/modules/system/layers/base/com/mysql/main目录下新增文件module.xml
内容如下:
请注意module:1.3的版本号,不同版本的WildFly可能需要的版本号不一样,这里WildFly10的版本号是1.3,如果不知道当前的WildFly该配置什么版本号,可以在$WILDFLY_HOME/modules/system/layers/base/com目录下随便找一个现有的module.xml文件,看一下xmlns="urn:jboss:module:x.x"就知道了,然后新增的MySql的module也按x.x版本号即可;
请保证resource-root这个值path的值跟你拷贝的驱动的文件名一致;
启动或重启WildFly,在在$WILDFLY_HOME/bin目录下,运行
[root@localhost bin]# ./jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[domain@localhost:9990 /]
运行下面的命令:
[domain@localhost:9990 /] /profile=full/subsystem=datasources/jdbc-driver=mysql:add(\
driver-name=mysql,\