Guido García Guido García - 1 year ago 110
Java Question

Autodiscover JAX-RS resources with CXF in a Spring application

Is it possible with Apache CXF (2.7.0) to automatically discover JAX-RS resources in the classpath? That is, classes annotated with


I am using CXF in a Spring application and I have to manually declare the resources with the following XML, even if the resources are successfully discovered by Spring
<context:component-scan ...>

<jaxrs:server id="myService" address="/myService">
<ref bean="myResource1" />
<ref bean="myResource2" />
<ref bean="myResource3" />

I would like to avoid it (as I can do with other JAX-RS implementations such as resteasy) because in my case it is harder to maintain, and it forces me to declare my bean dependencies in the Spring XML configuration file.

Answer Source

It doesn't look like there's a way to do this with Spring configuration at this time in CXF 2.7. If you look at resteasy they've implemented a BeanFactoryPostProcessor that looks for @Path and @Provider. Something similar could be probably be done in CXF but it doesn't appear to be implemented yet. Looks like you're not the only one interested CXF-3725

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download