0

I fail to correctly reference a service interface with the @Reference Annotation.

public class TestServiceProcessor implements Processor {

  @Reference
  private TestService testService;

The Service is up and running on the Karaf Instance and i can reference it with the blueprint file which does work fine.

 <bean id="translateOIDs"
 class="com.test.TestServiceProcessor">
 <property name="TestService" ref="testservice" />
 </bean>

 <reference id="testservice"
 interface="com.test.TestService"/>

The Service has been set up with the OSGI Component Annotations.

I already installed the scr feature and camel-scr on Karaf. I tried using the field strategy as well as the Event Strategy.

Do i need to further configure the Karaf Instance or am i using the @Reference Annotation in a wrong way?

1 Answers1

2

First you need to install the scr feature to enable declarative services. I guess you mean this with "src" feature.

Apart from this @Reference only works in DS components. So you class TestServiceProcessor must be annotated with @Component ... but then it can not be used in blueprint. DS and blueprint are mutually exclusive.

What you can do instead is leverage the http://aries.apache.org/modules/blueprint-maven-plugin.html.

In this case you need to annotate the bean class with @Named and do the inject with @Inject. You can then also reference annotated beans from the regular blueprint context by their id which can be set using @Named("yourid").

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64