How to configure a Datasource with JBoss 7
??A datasource is defined into the datasources subsystem.
Datasources in AS 7 are not defined anymore using -ds.xml file as you did for earlier JBoss AS releases
A Datasource can be configured either from the Command Line Interface or from the server main configuration file (standalone.xml/domain.xml).
In In the following example, we are configuring a MySQL Datasource by adding a new com.mysql module which is registered in the server main configuration file.
<datasource jndi-name="java:/MySqlDS" pool-name="MySQLPool"> <connection-url> jdbc:mysql://localhost:3306/jboss7db </connection-url> <driver> mysql </driver> <pool> <max-pool-size> 30 </max-pool-size> </pool> <security> <user-name> root </user-name> <password> admin </password> </security> </datasource> <drivers> <driver name="mysql" module="com.mysql"/> </drivers>
Now you need to register the com.mysql module under the modules/com/mysql/main folder. There you need to add two files: the module.xml definition and the JDBC jar library.
¦ ¦ +---main
¦ ¦ +-------module.xml
¦ ¦ +-------mysql-connector-java-5.1.17.jar
The module.xml contains basically the module name, the resources used and its dependencies.
<module xmlns="urn:jboss:module:1.0" name="com.mysql"> <resources> <resource-root path="mysql-connector-java-5.1.17-bin.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
Another available option is to install a JDBC driver into the application server is to simply deploy it as a regular JAR deployment.
This is particularly useful when you are running your application server in domain mode. In such a scenario, your deployments are automatically propagated to all servers to which the deployment applies; thus distribution of the driver JAR is one less thing for administrators to worry about.
Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version.
08:44:40,251 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "mysql-connector-java-5.1.17-bin.jar"
08:44:40,814 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
08:44:40,857 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) Bound data source [java:/MySQLDS]
08:44:40,857 INFO [org.jboss.as] (MSC service thread 1-2) JBoss AS 7.0.0.CR1 "White Rabbit" started in 15257ms - Started 111 of 168 services (57 services are passive or on-demand)
08:44:40,922 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "mysql-connector-java-5.1.17-bin.jar"