Java 将HttpservletRequest注入spring aop

Java 将HttpservletRequest注入spring aop,java,spring,aop,jersey-2.0,Java,Spring,Aop,Jersey 2.0,我有一个restful web服务(使用SpringJersey、Spring4.1.4和jersey 2.14) 我有一个春季AOP的建议 @Aspect public class MyAdvice { @Before(" @annotation(CustomAnnotation)") public void checkSomething(JoinPoint jp) throws AppException { for (Object o : jp.getArgs()) {

我有一个restful web服务(使用SpringJersey、Spring4.1.4和jersey 2.14)

我有一个春季AOP的建议

@Aspect
public class MyAdvice {

@Before(" @annotation(CustomAnnotation)")
public void checkSomething(JoinPoint jp) throws AppException {

    for (Object o : jp.getArgs()) {
        if(o instanceof HttpServletRequest){
            // do something
        }
    }
}
我的问题不是将HttpServletRequest作为方法参数传递,而是我可以从AOP内部以某种方式访问HttpServletRequest吗

我试过了

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); 
在checkSomething方法中,它抛出一个异常

org.glassfish.jersey.server.spring.scope.JaxrsRequestAttributes cannot be cast to org.springframework.web.context.request.ServletRequestAttributes

提前感谢各位。

您不能将org.glassfish.jersey.server.spring.scope.JaxrsRequestAttributes强制转换为org.springframework.web.context.request.ServletRequestAttributes。因为JaxrsRequestAttributes在其父层次结构中找不到ServletRequestAttributes。org.springframework.web.context.request.AbstractRequestAttributes是两者的父类。
org.glassfish.jersey.server.spring.scope.JaxrsRequestAttributes cannot be cast to org.springframework.web.context.request.ServletRequestAttributes