users@jersey.java.net

[Jersey] Can't Get jersey-spring3 Bridge To Work

From: Michael Iles <michael.iles_at_gmail.com>
Date: Mon, 30 Dec 2013 18:38:59 -0500

(Cross-posted to SO:
http://stackoverflow.com/questions/20849391/jersey-spring3-bridge-isnt-finding-my-resources.)

I'm using the Jersey / Spring bridge
(https://jersey.java.net/documentation/latest/spring.html) and I can't
get it to see my Jersey resources via a Spring XML config file.

(Spring 3.2, Jersey 2.5, jersey-spring3 2.5, jackson-jaxrs-json-provider 2.2.3.)

In my Spring config file I have

    <context:component-scan
base-package="com.fasterxml.jackson.jaxrs.json, com.mycompany.mappers,
com.mycompany.resources" />

SpringComponentProvider.initialize() succeeds, and
SpringComponentProvider.bindgets called for a bunch of classes (well,
actually just the stuff in the Jersey server's WADL package), but is
not called for my resource classes.

I can see that Spring is finding my resource:

    2013-12-30 16:47:24,246 [main]
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:215
 DEBUG Creating shared instance of singleton bean 'myResource'
    2013-12-30 16:47:24,246 [main]
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory:432
   DEBUG Creating instance of bean 'myResource'

The sample app referenced in the docs
(https://github.com/jersey/jersey/tree/2.5/examples/helloworld-spring-webapp)
defines a Jersey application subclass
oforg.glassfish.jersey.server.ResourceConfig and programmatically
registers resources. I was hoping to use a Spring XML config file to
bind resources, rather than hardcoding them. (This used to work in
Spring 1.)

What am I doing wrong? How can I get Jersey 2 to see my resources via
the Spring bridge?

Thanks,
Mike.