users@jersey.java.net

Re: [Jersey] ContainerRequestFilter as Spring component?

From: Paul Sandoz <Paul.Sandoz_at_ORACLE.COM>
Date: Wed, 22 Sep 2010 15:37:27 -0700

Hi Nico,

How are you registering the SecurityFilter with Jersey? are you
instantiating it yourself and programatically registering it?

Paul.

On Sep 20, 2010, at 1:16 AM, Nico Rehwaldt wrote:

> Hi,
>
> I am using Jersey 1.4 ea together with Spring 3.0 and the jersey-
> spring integration. Integrating Jersey and Spring works fine for
> resource classes. However I created an instance of
> ContainerRequestFilter to do some pre-processing of requests. The
> filter should be a spring component and should handle setting up the
> security context.
>
> Basically I want to have access to the database (the ORM-Layer) and
> I tried to accomplish this in two ways:
>
> @Component
> public class SecurityFilter implements ContainerRequestFilter {
>
> // UserManager is a declared spring component
> // Injecting it should work somehow
> @Autowired
> private UserManager userManager;
>
> // Entity Manager would help, too
> @PersistenceContext
> private EntityManager em;
>
> @Override
> public ContainerRequest filter(ContainerRequest request) {
> System.out.println(userManager);
> // prints out null on request
> }
> }
>
> I registered the Filter as a Spring compontent, but it does not seem
> as if it is recognized as such.
> Both injection of EntityManager and UserManager (a Spring bean as
> well) do not work.
>
> Any suggestions what I might be doing wrong?
>
> Greetings
> Nico