users@jersey.java.net

[Jersey] Re: Jersey test and Spring annotation configuration class

From: James Shaw <js102_at_zepler.net>
Date: Thu, 18 Oct 2012 22:04:48 +0100

On 8 October 2012 09:53, Varesh Tapadia <varesh.tapadia_at_gmail.com> wrote:
> Hi All,
>
> I am trying to integrate my code with the JerseyTest and am facing a issue.
>
> I don't have a spring-configuration.xml class. I use annotations for
> configuring my spring.
> How can I use this to pass the information to initialize my JerseyTest
> class.
>
> I noticed this as the way to implement it but I don't have a spring config
> file.
> <code>
> super(new WebAppDescriptor.Builder("my.package")
> .contextPath("test-rest")
> .contextParam("contextConfigLocation",
> "classpath:spring-test.xml")
> .servletClass(SpringServlet.class)
> .contextListenerClass(ContextLoaderListener.class)
> .build());
> </code>
>
> Also, I wanted to run this test inside another framework. Because of this, I
> already have a applicationContext object available. Can I use it (inject
> into the Grizzly server)
>
> I am using the following
>
> <dependency>
>
> <groupId>com.sun.jersey.jersey-test-framework</groupId>
>
I've got this working recently. I don't have the source code to hand,
but I needed to make my own Grizzly TestContainerFactory that accepts
a Servlet instance, not just a Servlet class name. Then, if I
remember correctly, you can override getDefaultContext() in
SpringServlet and pass your own ApplicationContext through. That way,
you're now sharing the Spring context between your test and the
servlet container.

Hope that helps