Hi,
You need to use @Component with service.exported.* properties and normal JAX-RS
annotations:
@Component(service=TaskServiceRest.class,
property={"service.exported.interfaces=*",
"service.exported.configs=org.apache.cxf.rs",
"org.apache.cxf.rs.address=/tasklistRest"})
@Path("")
public class TaskServiceRest {
@Reference
TaskService taskService;
...
Take a look example from Christian Schneider blog:
https://github.com/cschneider/Karaf-Tutorial/blob/master/tasklist-ds/service/src/main/java/net/lr/tasklist/service/TaskServiceRest.java
http://www.liquid-reality.de/display/liquid/2015/06/30/Apache+Karaf+Tutorial+part+10+-+Declarative+services
You don't required to use DOSGi.
Regards,
Andrei.
> -----Original Message-----
> From: Oliver Schweitzer [mailto:[email protected]]
> Sent: Dienstag, 3. Januar 2017 13:39
> To: [email protected]
> Subject: REST Service with Annotation Based Declarative Services - How?
>
> Hi,
>
> Backstory: We migrated our whole application/custom Karaf distribution from
> Blueprint to Declarative Services, which went fine except some serious
> problems with getting our REST API to run.
>
> The snippet below shows how we had wired the REST components using
> blueprint. This worked fine.
>
> Now I want to do essentially the same using annotation based Declarative
> Services.
>
> - How would I translate the below config to annotations on
> myResource/myOtherResource?
> - Do I need DOSGI for that? If yes, then I have a problem
> https://issues.apache.org/jira/browse/DOSGI-253
>
> Best regards,
>
> Oliver
>
> —————————
>
> <blueprint <<<<snip>>>>>
> <bean id="exceptionMapper" class="mypackage.ServiceExceptionMapper" />
>
> <bean id="jsonProvider"
> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
> <bean id="multipartProvider"
> class="org.apache.cxf.jaxrs.provider.MultipartProvider" />
> <bean id="originFilter" class="mypackage.ApiOriginFilter" />
>
> <bean id="swagger2Feature"
> class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
> <<<snip>>>
> </bean>
>
> <cxf:bus>
> <cxf:inInterceptors>
> <bean
> class="org.apache.cxf.transport.http.HttpAuthenticationFaultHandler">
> <property name="realm" value="karaf"/>
> </bean>
> </cxf:inInterceptors>
> <cxf:features>
> <cxf:logging />
> <bean
> class="org.apache.cxf.interceptor.security.JAASAuthenticationFeature">
> <property name="contextName" value="karaf" />
> <property name="reportFault" value="true" />
> </bean>
> </cxf:features>
> </cxf:bus>
>
> <jaxrs:server id="MyService" address="/rest">
> <jaxrs:serviceBeans>
> <ref component-id="myResource" />
> <ref component-id="myOtherResource" />
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref component-id="jsonProvider" />
> <ref component-id="multipartProvider" />
> <ref component-id="originFilter" />
> <ref component-id="exceptionMapper" />
> </jaxrs:providers>
> <jaxrs:features>
> <ref component-id="swagger2Feature" />
> </jaxrs:features>
> </jaxrs:server>
>
> </blueprint>