I found a solution.

I declared the following bean:
    <bean id="classLoader" class="org.apache.aries.util.AriesFrameworkUtil"
        factory-method="getClassLoader">
        <argument ref="blueprintBundle" />
    </bean>

And then injected it into my bean. Before the class must be loaded, I set the Thread context classloader as follows:
        if (classLoader != null) {
            this.oldTccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
        ... load the classes with the contextclassloader ...
        } finally {
            if (oldTccl != null) {
Thread.currentThread().setContextClassLoader(oldTccl);
            }
        }

That way the class gets loaded by the bundle classloader of the declaring bundle. In contrary to Aries, which sets the Tccl to an instance of org.eclipse.core.runtime.internal.adaptor.ContextFinder, the spring-extender sets it to the declaring bundle classloader, which in my opinion makes more sense.


Reply via email to