我创建了一个示例osgi插件并将其部署在WSO2-ESB容器中
现在我想在osgi包中使用Spring进行bean管理。所以我创建了一个 spring-beans.xml 文件,如下所示。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- Add DAO Impl bean entry here and Add bean reference as required -->
<bean id="xyzDAO" class="x.y.z.ABCImpl">
</bean>
<!-- Add Service Impl bean entry here and attach DAO reference -->
<bean id="abcService" class="x.y.z.ABCServiceImpl">
<property name="xyzDAO" ref="xyzDAO"/>
</bean>
然后我创建了一个类并使用 ClassPathXmlApplicationContext 来加载xml文件,如下所示
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-beans.xml");
我从 BundleActivator 调用了这个类,它在bundle启动时运行
当我将此插件部署到 [WSO2-HOME] / repository / components / dropins / 时,我得到以下异常。
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.mi.mts.userprofile.spring.test.util.SpringUtil.setApplicationContext(SpringUtil.java:17)
at com.mi.mts.userprofile.spring.test.activator.Activator.start(Activator.java:42)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.io.FileNotFoundException: class path resource [spring-beans.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 29 more
当我从eclipse运行这个插件时,它运行顺畅
我无法弄清楚为什么会发生这样的问题。如果您有任何建议或解决方案,请告诉我,以便我能解决。
提前谢谢。
答案 0 :(得分:0)
而不是部署到[WSO2-HOME] / repository / components / dropins,
在[WSO2-HOME] / repository / components / lib。
中部署必须重新启动服务器并再次检查。
并检查this。
答案 1 :(得分:0)
您需要解决Spring遇到的类路径问题。请参阅this related question的答案。