users@jersey.java.net

[Jersey] Re: Spring managed providers

From: Miles, Eric (CONT) <"Miles,>
Date: Thu, 14 Nov 2013 11:58:38 -0500

Component registry for JAX-RS components via package scanning is currently broken in Jersey 2.4.x. There is an open defect for this:

https://java.net/jira/browse/JERSEY-2175

Eric Miles

From: Cédric Thiébault <cedric.thiebault_at_gmail.com<mailto:cedric.thiebault_at_gmail.com>>
Reply-To: Jersey Users <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Thursday, November 14, 2013 11:51 AM
To: Jersey Users <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Spring managed providers


I’m using Jersey 2.4.1, Spring 3.2.4 and Jetty.
My classes annotated with @Provider are also annotated @Component because I need injection.
I’m testing with:

 * a ContainerRequestFilter (annotated with @Provider and @Component)
 * an ExceptionMapper (annotated with @Provider and @Component)
 * a resource (annotated with @Path and @Component)

I’ve configured Jersey to scan my packages with these providers.
When I access the resource, the injection in this resource is fine but my request never go threw the ContainerRequestFilter.
It seems that Jersey did not registered it…. even if it appears in the logs:
Spring managed bean, filterTest, registered with HK2.

Did I miss something in my configuration of Jersey with Spring?

Here is my config.

ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.packages("org.obiba.jta.web");
resourceConfig.register(RequestContextFilter.class);
resourceConfig.property(ServletProperties.PROVIDER_WEB_APP, "true");
servletContextHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");

Here are the logs on startup:

INFO - org.glassfish.jersey.server.spring.SpringComponentProvider - Spring context lookup done.
INFO - org.glassfish.jersey.server.spring.SpringComponentProvider - Spring component provider initialized.
INFO - org.glassfish.jersey.server.spring.SpringComponentProvider - Spring managed bean, testResource, registered with HK2.
INFO - org.glassfish.jersey.server.spring.SpringComponentProvider - Spring managed bean, nullPointerExceptionMapper, registered with HK2.
INFO - org.glassfish.jersey.server.spring.SpringComponentProvider - Spring managed bean, filterTest, registered with HK2.
[...]
INFO - org.glassfish.jersey.server.ApplicationHandler - Jersey application initialized.
Root Resource Classes:
  org.obiba.jta.web.TestResource
Pre-match Filters:
   org.glassfish.jersey.filter.LoggingFilter
Global Response Filters:
   org.glassfish.jersey.filter.LoggingFilter
Global Reader Interceptors:
   org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor
Global Writer Interceptors:
   org.glassfish.jersey.filter.LoggingFilter

I’ve also posted this question on stackoverflow with a slightly different config:
http://stackoverflow.com/questions/19962472/jersey-spring-managed-providers

Thanks in advance!

Cedric
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.