Announcement Announcement Module

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
Using <import> with a spring bean xml file from an imported bundle Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using <import> with a spring bean xml file from an imported bundle


    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.

  • #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.