问题
Is it possible to apply a Spring handler interceptor or something similar to a Jersey Restful service? The Jersey service is built with Spring and is inside a Spring @Component?
I noticed that Spring allows the use of handler interceptors for controllers but cant find anything to work with my Jersey-Rest component
Thanks
回答1:
Jersey comes with its own servlet and therefore is pretty much outside of Spring MVC, which the Interceptors are part of. You can either:
- Use a Spring HTTP Filter to massage the HTTPServletRequest and the HTTPServletResponse around Jersey
- Use a Spring Handled Aspect around your Spring Component inside of Jersey to massage the Method invocation and result.
This guy here did a great job summing up the nuts and bolts: http://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/
回答2:
I faced a similar problem and this how I solved it in Jersey. This works similar to HandleInterceptor of Spring.
来源:https://stackoverflow.com/questions/13805674/applying-interceptor-to-jersey-restful-service-wired-as-spring-component