简体   繁体   English

com.mysql.jdbc.Driver在karaf中找不到bundle

[英]com.mysql.jdbc.Driver not found by bundle in karaf

I have a bundle which is using mySQL.jdbc.driver , I have given the dependency in pom file,import-packages and copied mysql connector in lib, deploy folder , installed mysql driver using install wrap:mvn:mysql/mysql-connector-java/5.1.17, i mean I did all possible as per me, but still I am getting error message as under, FYI I am using karaf-4.0.0.M2, please help its road block for me, 我有一个使用mySQL.jdbc.driver的bundle,我已经在pom文件中提供了依赖,import-packages和lib中复制的mysql连接器,部署文件夹,使用install wrap安装了mysql驱动程序:mvn:mysql / mysql-connector- java / 5.1.17,我的意思是我尽我所能,但我仍然收到错误消息,因为我在使用karaf-4.0.0.M2,请帮助我的路障,

errorMessage = JDBC driver name is missing or not valid, cause = java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by portframeworkservice [this is my bundle name]

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by portframeworkservice [145]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)

Database drivers in OSGi are always a bit difficult as the most common approach outside OSGi using DriverManager is not really suitable for OSGi. OSGi中的数据库驱动程序总是有点困难,因为使用DriverManager的OSGi之外最常用的方法并不适合OSGi。

The best approach in OSGi is to use a DataSourceFactory which is standardized by the OSGi alliance. OSGi中最好的方法是使用由OSGi联盟标准化的DataSourceFactory。 Some database drivers already offer this. 一些数据库驱动程序已经提供了 For others pax-jdbc provides an adapter. 对于其他人,pax-jdbc提供了一个适配器。 For mysql the second case applies. 对于mysql,第二种情况适用。

So my advice is to use pax-jdbc like this: 所以我的建议是使用像这样的pax-jdbc:

feature:repo-add pax-jdbc 0.6.0
feature:install pax-jdbc-mysql

If you then do 如果你这样做

karaf@root()> service:list DataSourceFactory
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
 osgi.jdbc.driver.class = com.mysql.jdbc.Driver
 osgi.jdbc.driver.name = mysql
 service.bundleid = 52
 service.id = 110
 service.scope = singleton

So the feature offers you a ready to use DataSourceFactory. 因此,该功能为您提供了随时可用的DataSourceFactory。 You can bind it as an OSGi service and create a DataSource from it. 您可以将其绑定为OSGi服务并从中创建DataSource。 To make it even more convenient you can also use pax-jdbc-config and pax-jdbc-pool to create a ready to use pooled DataSource as a service. 为了使它更方便,您还可以使用pax-jdbc-configpax-jdbc-pool创建一个可立即使用的池化DataSource作为服务。

I have a complete tutorial for accessing databases in OSGi that shows this approach. 我有一个完整的教程,用于访问OSGi中显示此方法的数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM