Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Spring Bean Scope in Bundles
Spring Bean Scope in Bundles [message #672384] Fri, 20 May 2011 21:29 Go to next message
rshelley  is currently offline rshelley Friend
Messages: 59
Registered: April 2010
Member
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 #672393 is a reply to message #672384] Fri, 20 May 2011 21:59 Go to previous messageGo to next message
rshelley  is currently offline rshelley Friend
Messages: 59
Registered: April 2010
Member
I can also tell that the BeanC being accessed from BundleA isn't the original because the original has a BundleContextAware interface on it that sets the bundle context in BeanC, but the BeanC called from BundleA has no bundle context set... so they are clearly two separate instances of BeanC when they should be the same.
Re: Spring Bean Scope in Bundles [message #672404 is a reply to message #672393] Fri, 20 May 2011 22:36 Go to previous messageGo to next message
rshelley  is currently offline rshelley Friend
Messages: 59
Registered: April 2010
Member
I might have found the issue here, still investigating, but I think some JAR files from the other bundles got into the WAR, so when component scanning ran, it picked them up and used the local beans instead.
Re: Spring Bean Scope in Bundles [message #672419 is a reply to message #672404] Sat, 21 May 2011 00:35 Go to previous message
rshelley  is currently offline rshelley Friend
Messages: 59
Registered: April 2010
Member
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.
Previous Topic:Comparison between Virgo and WAS 7
Next Topic:The Missing HttpService
Goto Forum:
  


Current Time: Sat Apr 20 04:26:47 GMT 2024

Powered by FUDForum. Page generated in 0.03797 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top