Could not load JDBC driver class on Jboss as 7
hai_feng Nov 27, 2013 10:56 PMHi
I have a problem, the problem is described as follows:
There is a web application which datasource do not use JNDI.It Configure a datasource bean in the spring's configuration,the file of bean as follow:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&autoReconnect=true&generateSimpleParameterMetadata=true </value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>test</value>
</property>
</bean>
In spite of this application don't use JNDI datasource,we also have to configure database-drivern on Jboss as 7
As recommended, I created a module:
- in D:\jboss-as-7.1.1.Final\modules\com\microsoft\mysql\main, I copied the mysql-connector-java-5.1.7-bin.jar file
- in the same directory, I created the following module.txt file
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.mysql">
<properties>
<property name="jboss.api" value="unsupported"/>
</properties>
<resources>
<resource-root path="mysql-connector-java-5.1.7-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
- It has updated the D:\jboss-as-7.1.1.Final\standalone\configuration\standalone.xml file to include both the datasource and the driver
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.microsoft.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
But when I deploy the web application on the Jboss and start jboss, I always get the following error :
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
... 57 more
Faced with this problem,I has find solutions online.
The way solve this proplem on Tomcat is putting the mysql-connector-java-5.1.7-bin.jar to the Tomcat's Installation directory path:apache-tomcat-7.0.27\lib.
The way solve this proplem on the old version of Jboss is putting the mysql-connector-java-5.1.7-bin.jar to the the old version of Jboss's Installation directory path:jboss-5.0.0.Beta1\lib
But I don't find the same path in the Jboss as 7,and I try to put the mysql-connector-java-5.1.7-bin.jar to the path:
D:\jboss-as-7.1.1.Final\standalone\lib;
D:\jboss-as-7.1.1.Final\standalone\lib\ext;
D:\jboss-as-7.1.1.Final\modules
but they all can not work.
Finally,I summarize my question:
1.I want to know why I had configured the datasource-drivern in the Jboss as 7 but it can not load the mysql-connector-java-5.1.7-bin.jar ?
2.I want to know the sencond method about that where could I put the mysql-connector-java-5.1.7-bin.jar to the path of Jboss as 7's Installation directory path?
I need your help,thanks!