karaf-mongodb-com.mongodb.Mongo-ClassNotFoundException

karaf-mongodb-com.mongodb.Mongo-ClassNotFoundException,mongodb,apache-camel,apache-karaf,Mongodb,Apache Camel,Apache Karaf,我想在我的上下文中使用mongodb组件。我已经在karaf中安装了feature camel mongodb,当我完成bundle:list时,我会得到 显示Mongo Java驱动程序已安装并正在运行 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001

我想在我的上下文中使用mongodb组件。我已经在karaf中安装了feature camel mongodb,当我完成bundle:list时,我会得到

显示Mongo Java驱动程序已安装并正在运行

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring
       http://camel.apache.org/schema/spring/camel-spring-2.0.0.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring"> 
  <!-- <camelContext  xmlns="http://camel.apache.org/schema/blueprint"> -->
    <route>
      <from uri="rabbitmq://localhost:5672/A?username=guest&amp;password=guest&amp;autoDelete=false&amp;routingKey=source_q&amp;queue=source_q&amp;exchangeType=topic"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="mongodb:mongo?database=mongo_poc&amp;collection=camel&amp;operation=save"/>
    </route>
  </camelContext>

  <!-- Mongo DB -->
  <bean id="mongo" class="com.mongodb.Mongo">
    <constructor-arg index="0" value="localhost" />
  </bean>


</beans>
我还包括

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>2.11.3</version>
</dependency>
在我的camel bundle项目的pom.xml中


请帮帮我。我不确定这里缺少什么。

我通过在标记下的by camel bundle项目的pom.xml中添加所需的包来修复此问题

karaf@root()> Exception in thread "SpringOsgiExtenderThread-8" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camel-3': Invocation of init method failed; ne
sted exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mongodb.Mongo] for bean with name 'mongo' defined in URL [bundle://149.23:0/META-INF/spring/
camelContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-bundle]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
        at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mongodb.Mongo] for bean with name 'mongo' defined in URL [bundle://149.23:0/META-INF/spring/camelCo
ntext.xml]; nested exception is java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-bundle]
        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1275)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
        at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1344)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:355)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:334)
        at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1178)
        at org.apache.camel.spring.CamelContextFactoryBean.getBeanForType(CamelContextFactoryBean.java:188)
        at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:145)
        at org.apache.camel.osgi.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:64)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-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:358)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
        at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1296)
        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1267)
        ... 24 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.Mongo not found by demo.camel-bundle [149]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
        at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1844)
        at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)
        at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
        ... 30 more
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>2.11.3</version>
</dependency>
<plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.3</version>
        <!--
         | the following instructions build a simple set of public/private classes into an OSGi bundle
        -->
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
            <Bundle-Version>${pom.version}</Bundle-Version>
            <Import-Package>com.mongodb, demo.service;version="${pom.version}"
                            ^^^^^^^^^^^ </Import-Package>
            <Include-Resource>src/main/resources</Include-Resource>
          </instructions>
        </configuration>
</plugin>