users@jersey.java.net

Jersey-test with Spring

From: Joshua Braegger <rckclmbr_at_gmail.com>
Date: Tue, 5 Oct 2010 13:25:21 -0600

Hi,

I am having an issue getting Jersey tests working with Spring. I have a
unit test constructor defined as follows:

    public PushNotificationServiceTest()throws Exception {
        super((new WebAppDescriptor.Builder("com.example.resource")
                .contextParam("contextConfigLocation",
"classpath:/applicationContext.xml")
                .contextPath("/")
                .servletClass(SpringServlet.class)
                .contextListenerClass(ContextLoaderListener.class)
                .requestListenerClass(RequestContextListener.class)
                .build()));
    }

and a test that gets a simple resource that injects a service, which uses
spring to handle dependency injection of another dependency. Everything
with Jersey is fine, but Spring is not working at all.

I have included "jersey-test-framework-http" v1.4-ea06 as a maven
dependency. The container starts up just fine, and locates the resources
just fine, but nothing in spring works. Even @Inject annotations work,
since they're used by Jersey, but any spring dependency injection does not
work -- I just get a NullPointerException thrown. In fact, if I change the
name of "applicationContext.xml" to something like "bogus.xml", it doesn't
even throw a FileNotFoundException like I'm assuming it should... so it's
not even *trying* to initialize spring beans. The application works great
when the war is normally deployed.

This happens with all containers (grizzly, inmemory, etc)

Any help would be appreciated, and thanks in advance for your help
-Josh