これを行う方法は、OSGiサービスを利用することです。次のコマンドを使用してSpringDMにサービスを登録できます(これは通常、別のosgi-context.xmlファイルで行われ、コードベースがテスト目的でOSGiに依存しないようにします。この例では、 BContext.xmlで定義され、OSGiサービスとして参照されるidクリニック
<?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>
次に、消費バンドルのosgi-context.xmlで、サービスを参照します。以下の例では、最初のBeanのコードを利用するclinicという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>
この方法で、バンドル間の依存関係について考え、他のバンドルに必要なサービスのみをエクスポートするようになります。