-
May 10th, 2011, 06:23 AM
#1
Using <import> with a spring bean xml file from an imported bundle
Hi.
My question is simple. I have bundleA that defines contextA.xml. I want that another bundle can load that xml like it is in it's classpath.
Or, to put another way, <import resource="classpath*:contextA.xml"/> does not mean anything in an osgi environment and the xml is not loaded into the context, while it works in a JEE environment of course. I'm running on Karaf 2.2.0 that has spring-osgi 1.2.1 installed by default.
I'm wondering if there's a way to achieve this that is NOT defining some beans from A as osgi services. This is becaus I do not want to load the contextA.xml beans while A is loaded, that will result in a unique instance of those bean. I just want that any bundle that imports from A could load the contextA.xml beans.
The main purpose is not duplicate those contextA.xml in all the different bundles it is needed.
I also do NOT want to write some custom code in an Activator, cause, for example, I need that a web.xml that loads spring-web would work out of the box like it's doing now, just defining OsgiBundleXmlWebApplicationContext as the contextClass.
Thanks for any tip.
-
Jun 16th, 2011, 03:56 AM
#2
Yes, you could do this.
Just make your bundle with contextA.xml as a fragment bundle. Fragment bundle attaches to parent bundle Classloader so yours <import resource="classpath*:contextA.xml"/> would work fine.
Another way (I'm not sure about that) is to export package with yours xml file outside from your bean. Then any bean, that imports such package would have an ability to get xml file from classpath. But, I'm not sure, because it's uncommon behavior for osgi enviroment.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules