开发者

Include resources in bnd file

I am trying to create a bundle x from lets say from 3 dependancies

a.jar has spring-context.xml
b.jar has spring-cotext.xml
c.jar has spring-beans.xml

My x bundle should import all the a,b,c jar resources and merge them into a context xml in x.jar when bundle is created. is this possible?

i have a maven project a, b,c are maven jar modules. x is a bundle project which has d开发者_如何转开发epencies of a,b,c.

Please can anyone help ?


I'm sure this is possible, but you might have to write the actual code to do the merge of those XML files. Combining a, b and c into a bundle x is something that the available tooling can do for you. You can take a look at Bnd or one of the tools that uses Bnd under the covers (Maven Bundle Plugin and others).


What you have suggested (combining spring contexts from multiple bundles) goes against the principles underlying OSGi. You should not have bundles that are dependent on the context of other bundles.

You should handle the dependencies by utilizing OSGi Services. Because you are using spring context files, I'm assuming that you're using Spring-DM. You can register a service in Spring DM with the following (which is usually done in a seperate osgi-context.xml file to ensure that the code base is not dependent on OSGi for testing purposes. In this example, you would have a bean with the id clinic defined in BContext.xml, and which is referenced as an OSGi service

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/osgi"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/osgi  
        http://www.springframework.org/schema/osgi/spring-osgi.xsd
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <service id="osgiClinic" ref="clinic" interface="org.springframework.petclinic.repository.Clinic" />

</beans:beans>

Then in the consuming bundle's osgi-context.xml, you would reference the service. In the example below, you now have a bean called clinic that utilizes the code from the first bean.

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/osgi"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/osgi  
        http://www.springframework.org/schema/osgi/spring-osgi.xsd
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <reference id="clinic" interface="org.springframework.petclinic.repository.Clinic"/>

</beans:beans>

This way of doing things will make sure you think about the dependencies between your bundles and only export those beans that are necessary for other bundles.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜