users@jersey.java.net

[Jersey] ContainerRequestFilter as Spring component?

From: Nico Rehwaldt <1abiene_at_web.de>
Date: Mon, 20 Sep 2010 10:16:58 +0200

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