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

别等时光非礼了梦想. 提交于 2019-12-12 13:29:40

问题


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.


回答1:


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.




回答2:


Note that another reason for this error could be a missing mysql connector! Install with this command in Karaf shell:

install -s mvn:mysql/mysql-connector-java/5.1.18



来源:https://stackoverflow.com/questions/10400642/classnotfoundexception-com-mysql-jdbc-driver-not-found-while-using-service-mix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!