如何设置正确的Bean类路径

时间:2014-03-07 14:15:42

标签: java spring apache-camel

你好

我有这段代码:

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent" >
    <property name="location" value="classpath:prj.properties"/>
</bean>

在文件../META-INF/spring/my-contexts/foo.xml内,我得到java.lang.ClassNotFoundException

一切正常,XML文件位于../META-INF/spring/foo.xml

那么,如何从位于../META-INF/spring/*

之外的其他文件夹中的XML文件中实例化此bean

谢谢!

编辑1:添加错误输出

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)

1 个答案:

答案 0 :(得分:2)

这是Manifest.MF文件中缺少的导入。

您正在使用带有bundle的osgi应用程序服务器,这意味着,您的类路径是由MANIFEST.MF中的信息设置的

要解决此问题,您必须在Manifest中添加一个条目:     Import-Package:org.apache.camel.component.properties

您使用哪种工具生成清单?

如果在pom.xml中使用maven-bundle-plugin,请添加import-package标记。

<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>

另外,请查看maven-bundle-plugin documentation