Aller au contenu | Aller au menu | Aller à la recherche


JBoss AS 7 : Datasource

How to configure a Datasource with JBoss 7?

JBoss AS 7 : Create, configure and deploy a MySQL datasource

With JBoss7, you need to register the com.mysql module under the new modules/com/mysql/main folder. There you need to add two files: the module.xml definition and the JDBC jar library.

modules
+---com
¦   +---mysql
¦   ¦    +---main
¦   ¦    +---module.xml  
¦   ¦    +---mysql-connector-java-5.1.18-bin.jar
jboss-as-7/modules/com/mysql/main/module.xml
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
   <resources>
      <resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
   </resources>
 
   <dependencies>
      <module name="javax.api"/>
      <module name="javax.transaction.api"/>
   </dependencies>
</module>

Configure your datasources

C:\jboss-as-7\standalone\configuration\standalone.xml

<subsystem xmlns="urn:jboss:domain:datasources:1.0">
            <datasources>
//...
				<drivers>
				   <driver name="mysql" module="com.mysql"/>
				</drivers>	
 
				<datasource jndi-name="java:/MySqlDS" pool-name="MySQLPoolFirstPoolName">
					<connection-url>jdbc:mysql://localhost:3306/myDB</connection-url>
					<driver>mysql</driver>
					<pool>
						<max-pool-size>30</max-pool-size>
					</pool>
					<security>
						<user-name>myMysqlUser</user-name>
						<password>myMysqlPassword</password>
					</security>
				</datasource>
//...
            </datasources>

Ressources

DataSource Jboss 7