Reputation: 997
I am trying to deploy a WildFly KeyCloak Server in standalone
Mode. This works fine when I just do nothing but now I want to add a Datasource
of MySQL
.
Therefore I have to add a driver i am using the: mysql-connector-java-8.0.20.jar
.
To add the driver I put it inside /modules/com/mysql/main/
. Then I add a module.xml
file:
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-8.0.20.jar"/>
</resources>
<dependencies>
<module name="javax.api">
<module name="javax.transaction.api"/>
</dependencies>
</module>
Then I add the follwing in the standalone.xml
:
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
When I then deploy the Server with the standalone.bat
I get following error:
16:57:43,962 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 32) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"
Cheers !!
Upvotes: 1
Views: 1515
Reputation: 396
Try this:
Put the connector in /standalone/deployments then start the server again. It will deploy and register the connector in the system.
Next add this to your standalone.xml datasources.
<datasource jndi-name="java:/jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true">
<connection-url>jdbc:mysql://localhost:3306/keycloak?useSSL=false&characterEncoding=UTF-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Africa/Luanda</connection-url>
<driver>mysql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>15</max-pool-size>
</pool>
<security>
<user-name>usernameforthedb</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<validate-on-match>true</validate-on-match>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
Change your serverTimezone accordingly. And, for safety, add the database in mysql before starting the server.
Restart again.
P.S. keep this whre it is of course:
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
Upvotes: 0
Reputation: 17455
Simplify your life so that the next time you do this it's not manual. Create a file that contains something like:
embed-server --server-config=standalone.xml --std-out=echo
batch
#
# remove the default provided datasource
#
/subsystem=datasources/data-source=KeycloakDS/:remove
#
# add the module
#
module add --name=com.mysql --resources=${user.home}/Downloads/mysql-connector-java-8.0.20/mysql-connector-java-8.0.20.jar --dependencies=javax.api,javax.transaction.api
#
# create the driver
#
/subsystem=datasources/jdbc-driver=mysql:add(driver-name="mysql",driver-module-name="com.mysql",driver-class-name=com.mysql.cj.jdbc.MysqlXADataSource)
#
# create the datasource
#
/subsystem=datasources/data-source=KeycloakDS/:add(connection-url=jdbc:mysql://localhost:3306/keycloak,driver-name=mysql,jndi-name=java:jboss/datasources/KeycloakDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=keycloak,user-name=keycloak)
run-batch
Run this with $KEYCLOAK_HOME/bin/jboss-cli.sh --file=<the_file_name>
. Keyclock cannot be running when you run this script. And the user and database must already exist before you restart Keycloak.
What this does is
The advantage is that this is repeatable if you need to install again or into a different server.
And do you need the XA driver? If I was developing in Wildfly for myself I might need XA but I don't think Keycloak is going to take advantage of it.
Upvotes: 4