Applying interceptor to Jersey RESTful service wired as Spring @Component

我的梦境 提交于 2019-12-11 00:22:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!