ThR37
ThR37

Reputation: 4085

How can I provide Spring with OSGi resources from a bundle fragment?

I am facing the following issue: I am developing an OSGi bundle with Spring and I would like to allow the developers who will use my bundle to add a Spring context file through a fragment.

These files will be use to configure my Spring beans (a similar existing example without Spring: configuration file in a fragment for org.apache.log4j).

I have to use the Spring framework for several reasons that are out of the scope of this question, but I can't use the following directive

<import resource="..."/>

because I am not even sure that some fragment will be available at run time (it being optional configuration), and I know that Spring will complain if it is unable to find the resource. Ideally, I would like to have something like this:

<import resource="my_default_configuration.xml"/>
<import resource="my_extended_configuration.xml"
        doesNotComplainIfAbsent="true"
        override="true"/>

Do you have any ideas to help me?

Thanks in advance.

Upvotes: 1

Views: 367

Answers (1)

artbristol
artbristol

Reputation: 32437

I think using OSGi properly would be a better way of doing it. Spring DM (AKA Gemini Blueprint) allows you to import and export Spring beans via OSGi. So your bundle could attempt to import all beans matching a specific interface, which developers using your bundle would export from their own bundle. It would still be optional, because you would end up with an empty list in your bundle if the developer chose not to provide any.

Upvotes: 1

Related Questions