|
|
Re: Bean factory post processors [message #725529 is a reply to message #725520] |
Thu, 15 September 2011 05:59 |
Tin N/A Messages: 46 Registered: December 2010 |
Member |
|
|
Nothing easier
It's just one bundle, attached to this post (it's an Eclipse STS project, but the bundle itself you can find in the target/ subdirectory).
So the aim is, as described in the first post, to be able to initialize only the selected services out of all the services that the bundle can provide. The logic for that is implemented in the test.bfpp.ServiceActivatingPostProcessor class. Each of the services has its own context file which the aforementioned class then loads and copies their bean definitions into current registry.
I actually lied in my first post - the bean factory post processor hook does get called, but the registry hook does not, and I want that one so that beans are defined early enough to be able to benefit from property placeholder post processing.
I'm testing this on Virgo 2.1, but with Spring updated to 3.0.5, so the registry hook should work (it was added in 3.0.1).
Thanks in advance, and any suggestions about a different approach to achieve the same goal described above are much appreciated!
|
|
|
|
Re: Bean factory post processors [message #725787 is a reply to message #725706] |
Thu, 15 September 2011 19:00 |
Tin N/A Messages: 46 Registered: December 2010 |
Member |
|
|
Thanks Dmitry!
Well, I read up on ManagedServiceFactory and it does look like it's designed with use cases in mind that are similar to mine. The thing is - Spring just makes it that bit more elegant to do using post processors, so it's worth pursuing doing it the "Spring way".
Is there a need to raise an issue/wish item in Virgo tracker to implement support for registry post processor, or is this already planned, or maybe can't be done because of Spring dependency (not sure how Spring framework usage is regulated between Eclipse and SpringSouce/VMWare).
And a related question - when you move the code in my example post processor class to the postProcessBeanFactory method (which does get called), a problem surfaces with Xerces apparently not being able to parse the "osgi" XML elements. It pauses for a while when starting the bean, as if it wanted to load namespace schemas from the net (i.e. from the HTTP URL defined in schema location), and then it dies with an error about not being able to find the "osgi:service" definition. Any ideas why that is - it seems like the XmlBeanFactory (the same happens if I only use XmlBeanDefinitionReader) object created in that method does not have access to the namespace schemas included with Spring bundles, but rather tries to load them directly from their URL locations?
[Updated on: Thu, 15 September 2011 19:02] Report message to a moderator
|
|
|
|
|
|
|
Re: Bean factory post processors [message #726659 is a reply to message #726043] |
Mon, 19 September 2011 07:44 |
Tin N/A Messages: 46 Registered: December 2010 |
Member |
|
|
It was an interesting read, thanks, although I'm not sure who won in that comments exchange It's good to know, even though SpringSource's focus shifted away from OSGi, there is a wider group of people still working on getting it ready for more complex uses.
Meanwhile, I discovered a way to programatically add bean and OSGi service definitions with current level of post processor support, and while it might not be optimal it does work:
1. Implement a BeanFactoryPostProcessor and a BundleContextAware in the same class
2. In the postProcessBeanFactory method do this:
a) create a new OsgiBundleXmlApplicationContext
b) call setBundleContext on the object from a)
c) call setConfigLocations on the object from a), with location of the XML file(s) describing beans and services you want to instance
d) call refresh on the object from a)
e) access getBeanFactory on the object from a) to get all bean definitions and use registerBeanDefinition to register it in the current bean factory
There might be a simpler way to do it that maybe doesn't require creating a whole application context, but at least this is a good start...
[Updated on: Mon, 19 September 2011 07:45] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03541 seconds