他の OSGi バンドルによって登録されたサービスを追跡する参照リスナー クラスを持つ OSGi バンドルがあります。次のように設計図を使用して参照リスナーを構成し、必要なすべての Aries バンドルを Felix にデプロイしました。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
<reference-list id="ServiceList" interface="com.test.MyService" availability="optional">
<reference-listener bind-method="bind" unbind-method="unbind">
<bean class="com.test.MyServiceMonitor" />
</reference-listener>
</reference-list>
</blueprint>
この構成ではすべてがうまく機能し、サービスが行き来するときに MyServiceMonitor クラスの bind メソッドと unbind メソッドが呼び出されます。次のステップとして、bind メソッドでデータベースにもデータを書き込む必要があるため、MyServiceMonitor にエンティティ マネージャーを挿入し、Bean タグを次のように変更してトランザクションを作成しようとしました。
<bean class="com.test.MyServiceMonitor">
<tx:transaction method="bind" value="RequiresNew" />
<jpa:context property="entityManager" unitname="myunit" />
</bean>
bind メソッドのトランザクションを作成しようとすると、バンドルを開始すると以下の例外が発生します。tx:transaction タグを削除すると、バンドルは問題なく開始されますが、同じブループリント構成で他の (非参照リスナー) Bean でエンティティ マネージャーとトランザクションを使用できます。
OSGi に比較的慣れていないので、これが予期される動作であるかどうか、またそうである場合、参照リスナー内で DB 操作を実行する適切な方法は何かを理解できませんでした。それに関する洞察はありますか?
2013-07-11 12:40:12,592 | ERROR | 20 - org.apache.aries.blueprint - 1.1.0 | org.apache.aries.blueprint.container.BlueprintContainerImpl | Unable to start blueprint container for bundle com.test.my-bundle
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to convert value BeanRecipe[name='#recipe-2'] to type class java.lang.Object
at org.apache.aries.blueprint.di.CollectionRecipe.internalCreate(CollectionRecipe.java:92)
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)
at org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe.createListeners(AbstractServiceReferenceRecipe.java:246)
at org.apache.aries.blueprint.container.ReferenceListRecipe.internalCreate(ReferenceListRecipe.java:74)
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)
at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: listener, getter: null, setter: [class org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe$Listener.setListener(class java.lang.Object)]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)
at org.apache.aries.blueprint.di.CollectionRecipe.internalCreate(CollectionRecipe.java:90)
... 25 more
Caused by: org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to create proxy for bean #recipe-3 in bundle com.test.my-bundle version 1.0.0.SNAPSHOT
at org.apache.aries.blueprint.container.BeanRecipe.addInterceptors(BeanRecipe.java:771)
at org.apache.aries.blueprint.container.BeanRecipe.wrap(BeanRecipe.java:841)
at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:149)
at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:402)
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:394)
at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)
... 31 more
Caused by: org.apache.aries.proxy.UnableToProxyException: The class com.test.MyServiceMonitor is not an interface and therefore a proxy cannot be generated.
at org.apache.aries.proxy.impl.JdkProxyManager.getInterfaces(JdkProxyManager.java:43)
at org.apache.aries.proxy.impl.JdkProxyManager.createNewProxy(JdkProxyManager.java:36)
at org.apache.aries.proxy.impl.AbstractProxyManager.createDelegatingInterceptingProxy(AbstractProxyManager.java:75)
at org.apache.aries.proxy.impl.AbstractProxyManager.createInterceptingProxy(AbstractProxyManager.java:53)
at org.apache.aries.blueprint.container.BeanRecipe.addInterceptors(BeanRecipe.java:767)
... 38 more