Reputation: 484
I have this snipped of code:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent" >
<property name="location" value="classpath:prj.properties"/>
</bean>
inside the file ../META-INF/spring/my-contexts/foo.xml
and I'm getting a java.lang.ClassNotFoundException
.
All works fine the XML file is located here ../META-INF/spring/foo.xml
So, how can I instantiate this bean from a XML files located in another folder than ../META-INF/spring/*
karaf@root> Exception in thread "SpringOsgiExtenderThread-55" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find cl
ass [classpath:org.apache.camel.component.properties.PropertiesComponent] for bean with name 'properties' defined in OSGi resource[classpath
:META-INF/spring/my-contexts/foo.xml|bnd.id=247|bnd.sym=my.foo.bundle]; nested exce
ption is java.lang.ClassNotFoundException: classpath:org.apache.camel.component.properties.PropertiesComponent not found from bundle [my.foo.bundle]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1261)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.j
ava:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1330)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:896)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566
)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:89
5)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionAppli
cationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplication
Context.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionA
pplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.ru
n(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Thread.java:662)
Upvotes: 1
Views: 2363
Reputation: 3652
This is a missing import in your Manifest.MF file.
You are using an osgi application server with a bundle, this means, your classpath is set up by the information inside of MANIFEST.MF
To fix this issue, you have to add an entry inside of your Manifest: Import-Package: org.apache.camel.component.properties
Which tool are you using to generate your Manifest?
If you use maven-bundle-plugin in your pom.xml, add an import-package tag.
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
*,
org.apache.camel.component.properties
</Import-Package>
</instructions>
</configuration>
</plugin>
Also, take at look into the maven-bundle-plugin documentation
Upvotes: 2