users@jersey.java.net

Re: [Jersey] Jersey Spring Servlet (/dispatcher) not invoking Spring Interceptors

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 03 Nov 2009 18:21:35 +0100

On Nov 3, 2009, at 5:56 PM, Mahesh Venkat wrote:

> Hi,
>
> I am using Jersey 1.0.3.1 release with Spring 2.5 framework.
> I have defined a Rest Resource class as a Spring bean using @Scope &
> @Component annotation as well as a regular spring bean xml
> definition and is able to invoke it through the Spring container.
>
> I implemented the Paul's blog http://blogs.sun.com/enterprisetechtips/entry/jersey_and_spring
> and defined the application context. I defined a separate Spring
> Dispatcher using the JerseySpring Servlet and its xml definition has
> reference to a bunch of interceptos.
>
> However I am finding that none of the interceptors are invoked.
>
> I also tried the regular Spring way of adding the rest Resource bean
> in the standard DispatcherServlet-servlet.xml with a reference to
> the interceptors.
>
> Is this a bug in Jersey Spring Rest Servlet or I am missing
> somewhere in my configuration?

Hard to say, i do not know much about the Spring DispatcherServlet and
interceptors.

Are the resource classes still managed by Spring even if interceptors
are not invoked?


The Jersey SpringServlet obtains the spring context by doing:

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

In 1.x releases it is possible to support a child context by declaring
a contextConfigLocation as a servlet init param. I dunno if that has
relevance or not.

Might be best if you can send me a simple maven project and reproduces
your issue.

Paul.


> One of the items i am curious about is the application context
> visibility. Check out http://www.dotkam.com/2008/07/09/spring-web-application-context-visibility/
> . I added DispatcherServlet-servlet.xml and applicationContext.xml
> as part of the root context.
>
> --
> Regards
> --Mahesh