Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Bean bound and immediately unbound Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean bound and immediately unbound

    I found this "problem" and thought it might happen to other new users of Spring OSGi so here is the observed problem and solution.

    Basically, a Spring bean from one bundle was being injected into another Spring bean in another bundle, but then being immediately destroyed.

    I have a standard springified bundle offering a service and another springified bundle consuming the service.

    Service provider
    Code:
       <osgi:service id="ddsOsgiService" ref="ddsService" interface="lhs.skybook.dds.core.DDSService" />
    Service user
    Code:
      <bean name="hello" class="com.lsy.efb.eff.spring.Helloworld"
            init-method="start" destroy-method="stop" >
            <property name="ddsService" ref="remoteDdsService"/>
      </bean>
    
    
        <osgi:reference id="remoteDdsService" interface="lhs.skybook.dds.core.DDSService"/>
    When starting the bundles the required service was correctly detected and injected by the Spring Extender module, but then immediately destroyed.

    Turning on trace I found the following:
    Code:
    16:22:18,890 DEBUG OsgiServiceBindingUtils:48 - Calling bind on org.springframework.osgi.service.importer.support.internal[email protected]24e801 w/ reference {lhs.skybook.dds.core.DDSService}={org.springframework.osgi.bean.name=ddsService, Bundle-SymbolicName=dds, Bundle-Version=1.0.0, service.id=30}
    
    16:22:18,890 DEBUG OsgiServiceBindingUtils:56 - Called bind on org.springframework.osgi.service.importer.support.internal[email protected]24e801 w/ reference {lhs.skybook.dds.core.DDSService}={org.springframework.osgi.bean.name=ddsService, Bundle-SymbolicName=dds, Bundle-Version=1.0.0, service.id=30}
    
    16:22:18,890 DEBUG ServiceDynamicInterceptor:461 - 1..x cardinality - looking for service [(objectClass=lhs.skybook.dds.core.DDSService)] at startup...
    
    16:22:18,890 DEBUG OsgiBundleXmlApplicationContext:273 - Publishing event in context [org.sprin[email protected]15bdc50]: org.springframework.osgi.service.importer.event.OsgiServiceDependencyWaitStartingEvent[source=org.springfram[email protected]1455d1c]
    
    16:22:18,890 DEBUG OsgiBundleXmlApplicationContext:273 - Publishing event in context [org.sprin[email protected]15bdc50]: org.springframework.osgi.service.importer.event.OsgiServiceDependencyWaitEndedEvent[source=org.springfram[email protected]1455d1c]
    
    16:22:18,906 DEBUG ServiceDynamicInterceptor:464 - Service retrieved [email protected]
    
    16:22:18,906 DEBUG DefaultListableBeanFactory:213 - Creating shared instance of singleton bean 'hello'
    16:22:18,906 DEBUG DefaultListableBeanFactory:383 - Creating instance of bean 'hello'
    16:22:18,906 DEBUG DefaultListableBeanFactory:459 - Eagerly caching bean 'hello' to allow for resolving potential circular references
    16:22:18,906 DEBUG DefaultListableBeanFactory:214 - Returning cached instance of singleton bean 'remoteDdsService'
    16:22:18,906 DEBUG CachedIntrospectionResults:151 - Not strongly caching class [com.lsy.efb.eff.spring.Helloworld] because it is not cache-safe
    16:22:18,906  INFO DefaultListableBeanFactory:399 - Destroying singletons in org.s[email protected]be76c7: defining beans [remoteDdsService,hello]; root of factory hierarchy
    16:22:18,906 DEBUG DefaultListableBeanFactory:447 - Retrieved dependent beans for bean 'remoteDdsService': [hello]
    16:22:18,906 DEBUG DisposableBeanAdapter:148 - Invoking destroy() on bean with name 'remoteDdsService'
    16:22:18,906 DEBUG OsgiServiceBindingUtils:69 - Calling unbind on org.springframework.osgi.service.importer.support.internal[email protected]24e801 w/ reference {lhs.skybook.dds.core.DDSService}={org.springframework.osgi.bean.name=ddsService, Bundle-SymbolicName=dds, Bundle-Version=1.0.0, service.id=30}
    16:22:18,906 DEBUG OsgiServiceBindingUtils:77 - Called unbind on org.springframework.osgi.service.importer.support.internal[email protected]24e801 w/ reference {lhs.skybook.dds.core.DDSService}={org.springframework.osgi.bean.name=ddsService, Bundle-SymbolicName=dds, Bundle-Version=1.0.0, service.id=30}
    16:22:18,906 DEBUG ServiceDynamicInterceptor:236 - Service reference [{lhs.skybook.dds.core.DDSService}={org.springframework.osgi.bean.name=ddsService, Bundle-SymbolicName=dds, Bundle-Version=1.0.0, service.id=30}] was unregistered and unbound from the service proxy
    16:22:18,906 ERROR OsgiBundleXmlApplicationContext:307 - Post refresh error
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hello' defined in URL [bundleentry://19/META-INF/spring/helloworld.xml]: Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'ddsService' of bean class [com.lsy.efb.eff.spring.Helloworld]: No property 'ddsService' found
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:288)
    	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:145)
    	at java.lang.Thread.run(Thread.java:619)
    
    full stack dump removed for brevity
    Looking at the root cause of the stack trace gave the answer:
    Code:
    Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'ddsService' of bean class [com.lsy.efb.eff.spring.Helloworld]: No property 'ddsService' found
    This immediately told me it was nothing to do with Spring OSGi but a standard Spring Bean definition problem. i.e. the getter/setter had incorrect syntax. Instead of setDdsServcie()/getDdsService() I had specified setDDSService()/getDDSService() to match the class type of the property DDSService and not the property name.

    In principle the any exception during standard bean initialisation in the Spring bundle OSGI service consumer will cause the pattern of behaviour as I have seen on a few other posts. So treat spring right and Spring OSGi will be as transparent as glass.
Working...
X