1

I have created one sample osgi plugin and deploy it in WSO2-ESB container.
Now I want to user Spring in osgi bundle for bean management.So I have created one spring-beans.xml file as shown below.

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

Then I have created one Class and use ClassPathXmlApplicationContext for loading xml file as shown below

ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-beans.xml");

I have called this class from BundleActivator which runs on bundle startup.
When i deploy this plugin into [WSO2-HOME]/repository/components/dropins/ i got the following exception.

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

When i run this plugin from eclipse it runs smoothly.
I can't figure out the problem why it's so happened.If you have any suggestion or solution then please let me know so I can resolve it.
Thanks in advance.

Community
  • 1
  • 1
Tejas Patel
  • 89
  • 4
  • 16

2 Answers2

0

Instead of deploy into [WSO2-HOME]/repository/components/dropins,

deploy in [WSO2-HOME]/repository/components/lib.

Must restart the server and check once again.

And also check this.

Community
  • 1
  • 1
Kanchetianeel
  • 189
  • 2
  • 3
  • 15
  • It is itself an OSGI bundle so no need to deploy it in **[WSO2-HOME]/repository/components/lib**. – Tejas Patel Jan 24 '14 at 11:19
  • "component/lib" is not the solution - it always requires a restart! We want to add bundles (.jar) without restarting. – Philipp Jan 29 '14 at 11:12
0

You need to address the classpath issues that you have with Spring. See the answer for this related question.

Community
  • 1
  • 1
Robin
  • 24,062
  • 5
  • 49
  • 58