How to configure a Datasource with JBoss 7

User Rating: 5 / 5

Star activeStar activeStar activeStar activeStar active

??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">
   <driver name="mysql" module="com.mysql"/>

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.

¦   +---mysql
¦   ¦    +---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">
     <resource-root path="mysql-connector-java-5.1.17-bin.jar"/>

      <module name="javax.api"/>
      <module name="javax.transaction.api"/>

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  [] (MSC service thread 1-3) Starting deployment of "mysql-connector-java-5.1.17-bin.jar"
08:44:40,814 INFO  [] (MSC service thread 1-2) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
08:44:40,857 INFO  [] (MSC service thread 1-5) Bound data source [java:/MySQLDS]
08:44:40,857 INFO  [] (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  [] (DeploymentScanner-threads - 2) Deployed "mysql-connector-java-5.1.17-bin.jar"