Add new Datasource (mysql) wildfly
Did you add a driver definition? Your datasources
subsystem should look something like this:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/jdbc/myds" pool-name="myds" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>foo</user-name>
<password>bar</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The driver
element in the data source definition must reference a driver
element by name. The module
attribute must match the name of your MySQL driver module.
Actually I meet the same problem (I could add the datasources and test connection successfully before) So I'm just confused and I find a way works for me:)
See my services and I find it stopped,and I started it then tried again,It works well again! Even though your service does not stop, maybe just restart it. I have to say it may not work for you if you never success to connect before,good luck~