JBoss AS 7 : Datasource
Par PlaceOweb le samedi, juillet 16 2011, 20:17 - JAVA - Lien permanent
Comment configurer une source de données avec JBoss 7 ?
JBoss AS 7 : Création, configuration et déploiement d'un datasource connecté à MySQL
Définition du module MySQL utilisant le connecteur java MySQL
Avec JBoss7, vous devez inscrire le module com.mysql dans votre nouveau dossier modules/com/mysql/main. Ici vous devez ajouter deux fichiers : module.xml de déclaration et la librairie JDBC jar.
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>
Configuration de vos 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>
Log lorsque le datasource c'est déployé correctement
18:29:24,363 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 26) JBAS010404: Deploying non-JDBC-compliant driver class com.m ysql.jdbc.Driver (version 5.1) ... 18:29:25,823 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010400: Bound data source [java:/MySqlDS]
Log lorsque le datasource n'a pas réussi à se déployer
Quand c'est en erreur avec <driver>mysql-connector-java-5.1.18-bin.jar</driver> au lieu de <driver>mysql</driver>
18:16:17,127 INFO [org.jboss.as.connector] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.6.Final) 18:16:17,190 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 26) JBAS010403: Deploying JDBC-compliant driver class org.h2.Dr iver (version 1.3) 18:16:17,196 INFO [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service 18:16:17,199 INFO [org.jboss.as.jaxr] (MSC service thread 1-2) Binding JAXR ConnectionFactory: java:jboss/jaxr/ConnectionFactory 18:16:17,248 INFO [org.jboss.as.mail.extension] (MSC service thread 1-1) JBAS015400: Bound mail session [java:jboss/mail/Default] 18:16:17,425 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 26) JBAS010404: Deploying non-JDBC-compliant driver class com.m ysql.jdbc.Driver (version 5.1) ... 18:16:18,498 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report JBAS014775: New missing/unsatisfied dependencies: service jboss.jdbc-driver.mysql-connector-java-5_1_18-bin_jar (missing) dependents: [service jboss.data-source.java:/MySqlDS]
Quand c'est en erreur avec <datasource jndi-name="MySqlDS" au lieu de <datasource jndi-name="java:/MySqlDS"
18:27:22,665 ERROR [org.jboss.as.controller] JBAS014601: Error booting the container: java.lang.RuntimeException: org.jboss.as.controller.persistence.Configurat ionPersistenceException: JBAS014676: Failed to parse configuration at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:161) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b] at java.lang.Thread.run(Unknown Source) [:1.7.0_02] Caused by: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:125) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b ] at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:187) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.server.ServerService.boot(ServerService.java:256) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b] ... 1 more Caused by: javax.xml.stream.XMLStreamException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[125,5] Message: "Jndi name have to start with java:/ or java:jboss/" at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$NewDataSourceSubsystemParser.readElement(DataSourcesExtension.java:723) at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$NewDataSourceSubsystemParser.readElement(DataSourcesExtension.java:279) at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:100) [staxmapper-1.0.0.Final.jar:1.0.0.Final] at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.0.0.Final.jar:1.0.0.Final] at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:897) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:319) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:120) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:97) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:100) [staxmapper-1.0.0.Final.jar:1.0.0.Final] at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:59) [staxmapper-1.0.0.Final.jar:1.0.0.Final] at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:117) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b ] ... 4 more Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[125,5] Message: "Jndi name have to start with java:/ or java:jboss/" at org.jboss.as.controller.SimpleAttributeDefinition.parse(SimpleAttributeDefinition.java:154) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.as.controller.SimpleAttributeDefinition.parseAndSetParameter(SimpleAttributeDefinition.java:207) [jboss-as-controller-7.1.0.CR1b.jar:7.1.0. CR1b] at org.jboss.as.connector.subsystems.datasources.DsParser.parseDataSource(DsParser.java:544) at org.jboss.as.connector.subsystems.datasources.DsParser.parseDataSources(DsParser.java:193) at org.jboss.as.connector.subsystems.datasources.DsParser.parse(DsParser.java:164) at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$NewDataSourceSubsystemParser.readElement(DataSourcesExtension.java:715) ... 14 more
Quand c'est KO, car 2 datasources ont le même pool-name="MySQLPool"
18:34:46,249 ERROR [org.jboss.as.controller.management-operation] Operation ("add") failed - address: ([ ("subsystem" => "datasources"), ("data-source" => "MySQLPool") ]) - failure description: "JBAS014803: Duplicate resource [ (\"subsystem\" => \"datasources\"), (\"data-source\" => \"MySQLPool\") ]"
Ressources
DataSource Jboss 7
- JBoss AS 7 : Create, configure and deploy a MySQL datasource
- Data Source Configuration in AS 7
- How to configure a Datasource with JBoss 7
- How do I migrate my application from AS5 or AS6 to AS7 Update the DataSource Configuration, Define the datasource, Install the JDBC driver, Installing a JDBC Driver as a Deployment, Configure the datasource for Hibernate or JPA, Update application JNDI namespace names, Modify your application code to follow the new JNDI namespace rules