users@jersey.java.net

Re: [Jersey] Jersey-test and Spring

From: Srinivas Naresh Bhimisetty <shri.naresh_at_gmail.com>
Date: Thu, 7 Oct 2010 09:31:41 +0530

Joshua,

  I guess the jersey-test-framework-http module which runs the tests on the
HTTPServer, doesn't support Spring apps, since HTTPServer doesn't provide
the support.

Probably, you should try using the jersey-test-framework-grizzly /
jersey-test-framework-embedded-glassfish / jersey-test-framework-external
modules, i.e., either try running your tests on Grizzly Web Server or
Embedded GlassFish or an external container.

Please refer the spring-annotations sample [1] for more info.

[1]
http://download.java.net/maven/2/com/sun/jersey/samples/spring-annotations/1.4/spring-annotations-1.4-project.zip

- Naresh

On Wed, Oct 6, 2010 at 9:17 PM, Joshua Braegger <rckclmbr_at_gmail.com> wrote:

> 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.
>
> Any help would be appreciated, and thanks in advance for your help
> -Josh
>