Configuring MySQL DataSource with @DataSourceDefinition in JBoss AS7

I can configure MySQL DataSource in standalone.xml file and it works fine. But I want to set up a DataSource using the @DataSourceDefinition annotation.

How to configure MySQL data source using @DataSourceDefinition in JBoss AS7?

I have already tried:

 @DataSourceDefinition( className = "com.mysql.jdbc.Driver", name = "java:global/jdbc/MyDS", serverName="localhost", portNumber=3306, user = "root", password = "admin", databaseName = "test" ) @Startup public class DBConfig { } 

along with this persistence.xml :

 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="javaee6-app" transaction-type="JTA"> <jta-data-source>java:global/jdbc/MyDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> </persistence> 

I have a mysql connector jar file in WEB-INF/lib .

But when I deploy the application, I get this error:

(DeploymentScanner-threads - 2) {"JBAS014653: The composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: services with missing / inaccessible dependencies" => ["jboss.persistenceunit. \" Javaee6-app.war # javaee6-app \ "jboss.naming.context.java.global.jdbc.MyDSMissing [jboss. persistenceunit. \" javaee6-app.war # javaee6-application \ " jboss.naming.context.java.global.jdbc.MyDS] "]}}}

+8
java mysql java-ee-6
source share
3 answers

I figured it out myself.

The JBoss AS7 scanning process seems to have some drawbacks. According to the Java EE 6 specification, it should scan @DataSourceDefinition annotations on any classes. But it works great if we put it in a class with @Stateless .

 @DataSourceDefinition( className = "com.mysql.jdbc.Driver", name = "java:global/jdbc/MyDS", serverName="localhost", portNumber=3306, user = "root", password = "admin", databaseName = "test" ) @Stateless public class DBConfig { public void test() { //there should be atleast one method, so this dummy } } 
+4
source share

The following problem may also occur:

java.lang.ClassCastException: com.mysql.jdbc.Driver cannot be passed to javax.sql.DataSource

The param attribute className of @DataSourceDefinition should provide a DataSource implementation (see javadoc), not a driver class.

For MySQL, it could be:

 className = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource" className = "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" className = "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" // XA transaction 
0
source share

One suggestion is to configure the name of the data source in the standalone.xml or domain.xml file in jboss as 7. and configure the jQoss module in the mysql module. And try it.

Configure Mysql Connector jar See this link.

http://www.mastertheboss.com/jboss-datasource/how-to-configure-a-datasource-with-jboss-7

Data Source Configuration in Standalone.xml Link to this link

https://docs.jboss.org/author/display/AS71/DataSource+configuration

-one
source share

All Articles