当前位置: 首页 > 知识库问答 >
问题:

在OSGI bundle启动ClassNotFoundException

陆沈浪
2023-03-14

我有一个问题,我似乎无法独自解决。如果有一个OSGI捆绑包,它使用blueprint实例化应该部署到Karaf 3.0.0的对象。问题是,ClassNotFoundExceptions一直困扰着我,尽管相应的jar都位于捆绑包jar中。这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.kneipenapp</groupId>
    <artifactId>web-service</artifactId>
    <name>WebService</name>
    <version>0.0.1</version>
    <packaging>bundle</packaging>

    <dependencies>

        <!-- Database connection -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>2.0</version>
        </dependency>

        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-driver</artifactId>
            <version>5.1.29</version>
        </dependency>

        <!-- Camel -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
            <version>2.13.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.13.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-sql</artifactId>
            <version>2.13.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Http Handler exposing -->
        <dependency>
            <groupId>org.glassfish.grizzly</groupId>
            <artifactId>grizzly-http</artifactId>
            <version>2.3.11</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jersey -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.7</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Embed-Dependency>
                            *;scope=compile|runtime
                        </Embed-Dependency>
                        <Import-Package>
                            !*,
                            org.glassfish.grizzly.http,
                            org.apache.camel.component.sql,
                            org.osgi.framework
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是我的一个blueprint xml文件(该文件导致ClassNotFoundException):

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <!-- The camel context which will hold the routes -->
    <camelContext id="context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeContextRef ref="newElementContext"/>
    </camelContext>

    <!-- The OSGI service beans which will be used to publish the service through the Grizzly Http Server -->

    <bean id="endpoint" class="org.glassfish.jersey.server.internal.RuntimeDelegateImpl" factory-method="getInstance">
        <argument index="0" ref="endpointImplementation"/>
        <argument index="1" value="org.glassfish.grizzly.HttpHandler"/>
    </bean>

    <bean id="endpointImplementation" class="com.kneipenapp.service.ServiceEndpoint">
        <argument index="0" ref="context"/>
    </bean>

    <!-- The pooled connection -->
    <bean id="connectionFactory" class="org.apache.commons.dbcp2.DriverManagerConnectionFactory">
        <argument index="0" value="{{connection.url}}"/>
        <argument index="1" value="sqluser"/>
        <argument index="2" value="sqluserpw"/>
    </bean>

    <bean id="pooledSQLConnectionFactory" class="PooledSqlConnectionFactory">
        <argument index="0" ref="connectionFactory"/>
        <argument index="1" value="com.mysql.jdbc.Driver"/>
    </bean>

    <bean id="poolConfig" class="org.apache.commons.pool2.impl.GenericObjectPoolConfig">
        <property name="maxTotal" value="{{pool.maxConnections}}"/>
        <property name="maxIdle" value="{{pool.maxIdleConnections}}"/>
        <property name="minIdle" value="{{pool.minimumIdleConnections}}"/>
        <property name="maxWaitMillis" value="{{pool.waitInterval}}"/>
    </bean>

    <bean id="connectionPool" class="org.apache.commons.pool2.impl.GenericObjectPool">
        <argument index="0" ref="pooledSQLConnectionFactory"/>
        <argument index="1" ref="poolConfig"/>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.PoolingDataSource">
        <argument index="0" ref="connectionPool"/>
    </bean>

    <!-- The SQL endpoint used by the route -->
    <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
        <property name="dataSource" ref="dataSource"/>
    </bean>

</blueprint>

最后,这是我在尝试启动捆绑包时收到的异常和堆栈跟踪:

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to load class PooledSqlConnectionFactory from recipe BeanRecipe[name='pooledSQLConnectionFactory']
    at org.apache.aries.blueprint.di.AbstractRecipe.doLoadType(AbstractRecipe.java:195)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe.loadType(AbstractRecipe.java:161)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.loadClass(BeanRecipe.java:249)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.getType(BeanRecipe.java:895)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:323)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[4:org.apache.aries.blueprint.core:1.3.0]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:62)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:268)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[4:org.apache.aries.blueprint.core:1.3.0]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:62)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:268)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[4:org.apache.aries.blueprint.core:1.3.0]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:62)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:933)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[4:org.apache.aries.blueprint.core:1.3.0]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:681)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:378)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:276)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:245)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:235)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[2:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[2:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[2:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[2:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[2:org.apache.aries.util:1.1.0]
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:695)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:483)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4403)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2092)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1247)[16:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1219)[16:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1208)[16:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:503)[16:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:291)[16:org.apache.felix.fileinstall:3.2.6]
Caused by: java.lang.ClassNotFoundException: PooledSqlConnectionFactory not found by com.kneipenapp.web-service [80]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)[org.apache.felix.framework-4.2.1.jar:]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.7.0_25]
    at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1844)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)[org.apache.felix.framework-4.2.1.jar:]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:432)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.BlueprintRepository.loadClass(BlueprintRepository.java:410)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.container.GenericType.parse(GenericType.java:113)[4:org.apache.aries.blueprint.core:1.3.0]
    at org.apache.aries.blueprint.di.AbstractRecipe.doLoadType(AbstractRecipe.java:168)[4:org.apache.aries.blueprint.core:1.3.0]
    ... 63 more

如果有人知道如何解决这个问题,我会非常高兴听到

你好,帕斯卡

共有2个答案

郎飞龙
2023-03-14

您的连接池由构造函数创建

public GenericObjectPool(PooledObjectFactory

你们班=“PooledSqlConnectionFactory”impleme

你必须检查你给的参数(池

另外,我不知道Apache Aries,但也许y

应志用
2023-03-14

也许,您应该在指定 Bean 元素的类参数时使用完整的限定类名,包括包名。就像在'pooledSQLConnectionFactory'上面的'connectionFactory'豆子中一样。

 类似资料:
  • 大家好,我正在windows 7中使用xampp v3.2.1。我想在windows启动时自动启动它,但无法启动。 我尝试了这里提供的解决方案,但在服务中找不到任何东西。 我在D驱动器中安装了xampp,这就是为什么apache和mysql在从run打开services.msc时不显示在服务中的原因。 我已经从xampp控制面板的config(配置)按钮尝试过了,我选中了autostart(自动启

  • 我想在play应用程序(使用slick)启动之前,从docker compose文件(postgres和kafka实例)启动testcontainers。我想要这个,这样我就可以写一个端到端的测试。我似乎不明白这是怎么可能的。 Scala版本2.12.10 Testcontainer版本0.35.0 Play slick版本5.0.0 当我在没有“TestFunSpec”的情况下执行测试时,doc

  • XAMPP 3.2.1版安装在Windows 7上。它在Windows启动时没有自动启动。 尝试过:在中查看,它既不显示Apache也不显示MySQL。

  • 我使用elipse开发了一个插件项目,它工作正常。然后,我将该项目导出为归档文件,并将其导入到新的工作区。在执行项目时,新工作区出现以下空指针异常。在eclipse论坛上很少有关于此类错误的帖子,但我找不到任何具体的内容。如果你以前遇到过这样的问题,请告诉我。 !进入组织。日食魅力。设置。ui 2 0 2017-04-10 22:11:10.525 !消息java。lang.NullPointer

  • 问题内容: 我是Ubuntu的新手,我在Ubuntu 10.04中安装了XAMPP。当我启动XAMPP时,它说MySQL无法启动。 这是我的终端输出: 然后,当我转到时,我陷入了XAMPP初始屏幕,如果选择语言,则什么也不会发生。 问题答案: 我找到了答案。首先完全卸载lampp,然后重新安装。卸载之前,请使用以下命令停止lampp: 然后使用命令卸载/删除它 然后重新安装。

  • 我有一份Java申请。 应用程序有一个决定应用程序是否在启动时启动的设置。 目前,我通过在StartUp items文件夹中放置/删除快捷方式实现了这一点。 然而,我想知道是否有更好的方法来处理这种行为。 编辑 是的,是视窗。抱歉之前没有清除。 应用程序有一个UI,用户可以在其中触发操作,并且应用程序在运行时定期在后台运行一些任务。 @Peter,如何使用应用程序中的代码更改注册表?这种方法是否与