ブループリント(Aries)を使用して実行時に依存関係を解決したい場合があり、実装はそれを必要とする同じバンドルで定義されており、他のバンドルでは使用されません。単体テスト時に依存関係を簡単にモックできるように、このバンドル内の実装を抽象化しています。このサービスを独自のバンドルに入れると、まとまりが悪くなります。
実行時に、ブループリントは依存関係を待機していると言います。ブループリントを使用して、バンドル内の依存性注入を実現するにはどうすればよいですか?
<!-- Interface -->
<reference id="modelEntityMapper" interface="org.example.blog.rest.cxf.server.model.ModelEntityMapper" />
<!-- Implementation defined within same bundle -->
<bean id="modelEntityMapperImpl" class="org.example.blog.rest.cxf.server.model.impl.ModelEntityMapperImpl" />
<service ref="modelEntityMapperImpl" interface="org.example.blog.rest.cxf.server.model.ModelEntityMapper" />
<!-- Object which has dependency -->
<bean id="posts" class="org.example.blog.rest.cxf.server.BlogResourceImpl">
<property name="modelEntityMapper" ref="modelEntityMapper" />
</bean>
編集
@ christian-scheiderからの提案を試しましたが、BlueprintはまだModelEntityMapperを満たすサービスを待っています
XML
<!-- Interface -->
<reference id="modelEntityMapper" interface="org.example.blog.rest.cxf.server.model.ModelEntityMapper" />
<!-- Implementation defined within same bundle -->
<bean id="modelEntityMapperImpl" class="org.example.blog.rest.cxf.server.model.impl.ModelEntityMapperImpl" />
<!-- Object which has dependency -->
<bean id="posts" class="org.example.blog.rest.cxf.server.BlogResourceImpl">
<property name="modelEntityMapper" ref="modelEntityMapperImpl" />
</bean>
ログ
Bundle rest-cxf-server is waiting for dependencies [(objectClass=org.example.blog.rest.cxf.server.model.ModelEntityMapper)]