users@jersey.java.net

Re: [Jersey] Spring Jersey Integration

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 23 Jun 2009 09:52:31 +0200

On Jun 22, 2009, at 10:17 PM, Jonathan Holloway wrote:

> Hi all, many thanks for the links.
>
> I currently have an issue integrating Jersey into an existing Spring
> application that is using Jetty. My appContext is here:
>
> http://pbin.oogly.co.uk/listings/viewlistingdetail/3ecad2c73823995fa0f2a2686e3959
>
> An IllegalStateException is thrown as follows from
> WebApplicationContextUtils:
>
> throw new IllegalStateException("No WebApplicationContext found: no
> ContextLoaderListener registered?");
>
> I'm trying to initialize my Jersey components from within Spring
> itself.

There could be a chicken/egg issue here in that the Jersey
SpringServlet gets access to the WebApplicationContext by doing:

     private ConfigurableApplicationContext getDefaultContext() {
         final WebApplicationContext springWebContext =
                  
WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
         final ConfigurableApplicationContext springContext =
                 (ConfigurableApplicationContext) springWebContext;
         return springContext;
     }

i.e. it gets it from the servlet context, an attribute which can set
be set in a web.xml as follows:

    <web-app>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
      </listener>

(if you stick the applicationContext.xml in the same location as the
web.xml then AFAIK you do not require the above.

I do not know how the ConfigurableApplicationContext is obtained when
the configuration is defined within a spring configuration file as you
have done. Under such circumstances it might be necessary to extend
the SpringServlet and override the getDefaultContext (with changes to
make it protected).


> Looking at this code now it doesn't seem as if I'm
> going about it the right way. Can anybody suggest the correct way
> to go about doing this?
>

Most people i have seen utilizing Jetty/Jersey/Spring have configured
Jetty programatically, or using a web.xml, for example (just Jetty &
Jersey, no Spring):

   http://blog.reardonsoftware.com/2009/03/jersey-jetty-and-maven-helloworld.html

Paul.

> Many thanks,
> Jon.
>
>
>
> 2009/6/22 Paul Sandoz <Paul.Sandoz_at_sun.com>
>
> On Jun 20, 2009, at 8:23 PM, Jonathan Holloway wrote:
>
> Hi all,
>
> I'm looking for the latest up to date guide to integrating Spring
> and Jersey 1.1.0EA, I
> had ome issues with the SpringServlet complaining about needing
> ContextLoaderListener
> or ContextLoaderServlet.
>
> In addition to what Sudhakar sent see:
>
> https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/contribs/jersey-spring/index.html
> https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/package-summary.html
>
>
> Is the integration based off SpringMVC?
>
>
> No, there is currently no SpringMVC integration.
>
>
>
> Apologies, does such a guide exist at the moment? If not I'd be
> happy to put something together
> on the wiki for the latest version. Please let me know if I can help.
>
>
> Are you familiar with Spring MVC? if so perhaps you could suggest
> how we could integration that?
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>