Data source creation and MySQL driver problem
jsbournival May 26, 2009 10:32 AMI am having problems connecting to a MySQL data source inside of FuseESB 4 (SMX4). I have a typical app design, which needs to access a database. In terms of OSGi modular design, I have 4 bundles, it goes like this:
JAX-RS service > Spring "business" Service > DAO > data source (DBCP)
The web service + the spring bundle are wired correctly, it's the database connectivity that gives me this big headache. I created a data source bundle with the following manifest headers:
Manifest-Version: 1.0 Unversioned-Imports: * Bundle-Classpath: . Built-By: js Bundle-Name: Catamaran :: Tophits Data Sources bundle Created-By: Apache Maven Build-Jdk: 1.6.0_07 Bundle-Version: 0.0.1.SNAPSHOT Spring-DM-Version: 1.2.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: ds-bundle Import-Package: com.mysql.jdbc,javax.sql,org.apache.commons.dbcp,org.s pringframework.jdbc.datasource Archiver-Version: Plexus Archiver
This bundle is defining a DBCP DS bean like this:
<bean name="frDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/fr?autoReconnect=true"></property> <property name="username" value="fr"></property> <property name="password" value="password"></property> <property name="initialSize" value="2"></property> <property name="maxActive" value="5"></property> <property name="maxIdle" value="2"></property> </bean>
.. And exposing it as an OSGi service:
<osgi:service id="frDSOsgiService" ref="frDS" interface="javax.sql.DataSource" />
Then my DAO tries to use it:
<osgi:reference id="frDS" interface="javax.sql.DataSource" bean-name="frDS" />
But when I use the DataSource to create a connection ...
try { connection = getDataSourceFr().getConnection(); // ... } // ...
... it's throwing me the following exception
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1141) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <--cut for brevity--> Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found from bundle [tophits-integration-bundle] at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103) at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1134) ... 105 more Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at org.apache.felix.framework.searchpolicy.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:558) at org.apache.felix.framework.searchpolicy.ModuleImpl.access$100(ModuleImpl.java:59) at org.apache.felix.framework.searchpolicy.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1427) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at org.apache.felix.framework.searchpolicy.ModuleImpl.getClassByDelegation(ModuleImpl.java:421) at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1354) at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:746) at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99) ... 108 more
Note: I already have deployed the following supporting bundles:
Apache ServiceMix Bundles: commons-dbcp-1.2.2 (1.2.2.3)
MySQL AB's JDBC Driver for MySQL (5.1.6)
Spring JDBC (2.5.6)
Can someone tell me what I am doing wrong with this?
Thank you! Your thoughts are more than welcome.