Spring Bean Scope in Bundles [message #672384] |
Fri, 20 May 2011 17:29  |
Eclipse User |
|
|
|
I'm trying to figure out a weird scope issue with Spring beans and bundles.
BundleA depends upon an exported service from BundleB and BundleB uses a Spring bean we'll call BeanC (annotated with @Service).
When BundleB starts up, BundleB sets some stuff in BeanC (a list of objects). When BundleA calls to BundleB to look up an entry in BeanC's list, however, the list is empty. I can see from the object hashes that BeanC has different hashes. My register/undregister BundleB events work against one BeanC, and calls from BundleA work against a different instance.
I tried setting the BundleB and BeanC classes to @Scope("singleton"), but that doesn't help. Both get BeanC the same way, through @Autowired annotations. Even if I set the inner list of BeanC to static, I have the same problem - its as if two instance are created in two separate class loaders.
Any ideas why this is happening and how to get the same instance of BeanC for register/unregister bundle events as well as from exported service calls?
|
|
|
|
|
Re: Spring Bean Scope in Bundles [message #672419 is a reply to message #672404] |
Fri, 20 May 2011 20:35  |
Eclipse User |
|
|
|
Yep, that was the issue. My Maven POM was including JARs that weren't necessary (since they are being imported by OSGI) which caused two sets of classes to be created (one set from OSGI and one set from the WAR). I went back and did a lot of house cleaning in my POM and I was good to go.
One thing I discovered along the way was that my <osgi:...> context calls had to be in my applicationContext.xml file. They couldn't be in my foo-servlet.xml otherwise I'd get a "IllegalArgumentException: Required 'bundleContext' property was not set" error during startup of the WAR. Must be due to the order of operations during the start up of a Spring context.
|
|
|
Powered by
FUDForum. Page generated in 0.05173 seconds