jdbcapache-servicemixclassnotfound

ClassNotFoundException: com.mysql.jdbc.Driver not found while using service mix


I am using servicemix 4.4.1 with maven 3.0.4. I am very new to servicemix/java world - my main knowledge is c# / php.

I have added the below to one of my routes:

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  <property name="driverClass" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://10.10.10.29/ServiceMix"/>
  <property name="username" value="somet"/>
  <property name="password" value="somet"/>
</bean>

If i then deploy the route to service mix, i get:

ClassNotFoundException: com.mysql.jdbc.Driver not found

From some googling i found that i was missing some lines from my POM, so i added the following:

<osgi-import-package>
org.apache.servicemix.bundles.commons-dbcp
</osgi-import-package>

AND

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.commons-dbcp</artifactId>
<version>1.4_3</version>
</dependency>

I also ran the below so that servicemix knew about the bundles:

osgi:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-pool/1.5.4_4
osgi:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3

However, now when i attempt to start the bundle i get:

Error executing command: Could not start bundle mvn:com.boohoo/boohoo-esb-products-sage-internal/1.0-SNAPSHOT in feature(s) boohoo-esb-products-sage-internal-1.0-SNAPSHOT: Unresolved constraint in bundle boohoo-esb-products-sage-internal [256]: Unable to resolve 256.0: missing requirement [256.0] package; (package=org.apache.servicemix.bundles.commons-dbcp)

I also did some more googling which said i could add a manifest file to the project so that dynamic imports was allowed. Thus i added a new file called: MANIFEST.MF to the route of the project and added the following to the file:

Fragment-Host:
 org.apache.commons.dbcp 
DynamicImport-Package:
 *

But this has had no effect either. I feel like i am going round in circles. Any help/pointers would be great.

I hope everything makes sense, but if not, just say so and i'll try and explain it better.

Cheers.


Solution

  • Fixed the issue. I updated my code as follows:

     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://10.10.10.29/ServiceMix"/>
      <property name="username" value="something"/>
      <property name="password" value="something"/>
    </bean>
    

    POM:

    <osgi-import-package>
      org.apache.commons.dbcp
    </osgi-import-package>
    
    <dependency>
      <groupId>org.apache.servicemix.bundles</groupId>
      <artifactId>org.apache.servicemix.bundles.commons-dbcp</artifactId>
      <version>1.4_3</version>
    </dependency>
    

    Removed the manifest file. Uninstalled commons-pools from servicemix.