3

I have a problem which I just cannot seem to solve on my own. If have an OSGI Bundle which uses blueprint for instantiation of the Objects which should be deployed to Karaf 3.0.0. The problem is, that ClassNotFoundExceptions keep bothering me, allthough the corresponding jars are located in the bundles jar. This is my 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>

This is one of my blueprint xml files (this one is causing the 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>

Finally this is the Exception and Stacktrace I recieve when I try to start the bundle:

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

If someone has a clue how this could be solved, I'd be more than happy to hear it

Greetings, Pascal

4

2 回答 2

1

也许,您应该在指定 bean 元素的类参数时使用完整的类名,包括包名。就像在“pooledSQLConnectionFactory”上方的“connectionFactory”bean 中一样。

于 2014-03-25T09:41:37.153 回答
0

您的connectionPool由构造函数创建

public GenericObjectPool(PooledObjectFactory < T > factory, GenericObjectPoolConfig config) {...}

您的class="PooledSqlConnectionFactory"是从commons-pool2实现 PooledObjectFactory < T >还是 使用正确的覆盖、构造函数等 扩展BasePooledObjectFactory < T > ?

您必须检查您提供的参数(pooledSQLConnectionFactorypoolConfig)是否符合org.apache.commons.pool2.impl.GenericObjectPool的构造函数

另外,我不了解 Apache Aries,但也许您还检查了它如何与泛型一起使用。
请参阅 https://issues.apache.org/jira/browse/ARIES-960
https://issues.apache.org/jira/browse/ARIES-834

于 2014-03-25T14:15:23.243 回答