Reputation: 71
I have an application that has a datasource defined in context-common.xml and the details are loaded from my application.properties.
I tried to follow this tutorial from jBoss https://community.jboss.org/wiki/DataSourceConfigurationInAS7
So I added the mysql-connector-java-5.1.22 in this structure /modules/com/mysql/main/ and I added a module.xml with it. It reads:
<resources>
<resource-root path="mysql-connector-java-5.1.22.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
And in my standalone.xml:
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/cab;DB_CLOSE_DELAY=-1</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
I don't understand what I should do with the jndi-name? Do I even need it?I didn't use it when I was using JBoss 4.
Also, here is some more of the stack trace:
10:00:23,338 WARN [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) SQL Error: 0, SQLState: null
10:00:23,342 ERROR [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
10:00:23,347 WARN [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-2) Could not obtain connection metadata: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) [commons-dbcp-1.2.2.jar:1.2.2]
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) [commons-dbcp-1.2.2.jar:1.2.2]
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:83) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84) [hibernate-3.2.7.ga.jar:3.2.7.ga]
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2090) [hibernate-3.2.7.ga.jar:3.2.7.ga]
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2086) [hibernate-3.2.7.ga.jar:3.2.7.ga]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1311) [hibernate-3.2.7.ga.jar:3.2.7.ga]
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) [hibernate-annotations-3.4.0.GA.jar:3.2.7.ga]
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:863) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:782) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_20]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_20]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.cab-1.0-SNAPSHOT.war:main" from Service Module Loader]
Upvotes: 1
Views: 1303
Reputation: 14061
If I understood it correctly, your are shipping a connection pooling mechanism with your application (DBCP). You also seem to be shipping Hibernate by yourself, with Spring. You mentioned as well that you are loading the connection details from a properties file (also from your war file, I presume). If that's correct, then you don't need to do anything with the AS, and you can just as well ship your MySQL driver with your application.
But the real question seems to be why you are shipping so many things that are already provided by the AS. While this seemed like the default choice in the mid-2000s, modern applications should not be bundling a connection pooling (it is provided by the AS itself), or Hibernate (also provided by the AS via JPA), or Spring Beans (which most of the features can be easily replaced by CDI).
Upvotes: 1