title: Injecting transaction in OSGi reference listener with blueprint
body: <p>I have an OSGi bundle which has a reference listener class keeping track of services registered by other OSGi bundles. I have configured the reference listener with blueprint as follows and have deployed all the necessary Aries bundles in Felix:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;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"&gt;  
      &lt;reference-list id="ServiceList" interface="com.test.MyService" availability="optional"&gt;
          &lt;reference-listener bind-method="bind" unbind-method="unbind"&gt;
              &lt;bean class="com.test.MyServiceMonitor" /&gt;
          &lt;/reference-listener&gt;
      &lt;/reference-list&gt;
  &lt;/blueprint&gt;
  </code></pre>
  
  <p>Everything works well with this configuration and the bind and unbind methods of the MyServiceMonitor class are called when services come and go. As a next step I want the bind method to also write some data in the database so I tried to inject an entity manager in MyServiceMonitor and create a transaction by changing the bean tag as follows:</p>
  
  <pre><code>&lt;bean class="com.test.MyServiceMonitor"&gt;
      &lt;tx:transaction method="bind" value="RequiresNew" /&gt;
      &lt;jpa:context property="entityManager" unitname="myunit" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This attempt to create a transaction for the bind method results to the exception below when I start the bundle. The bundle is started without problems when I remove the tx:transaction tag while I have been able to use an entity manager and transactions in other (non reference listener) beans with the same blueprint configuration. </p>
  
  <p>Being relatively new to OSGi I haven't been able to figure out whether this is expected behaviour and if yes what is the proper way to perform DB operations inside a reference listener. Any insights on that?</p>
  
  <pre><code>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 &lt;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
  </code></pre>