当前位置: 代码迷 >> Java Web开发 >> 小弟我想知道在spring aop的环绕通知得到HttpServletReponse对象
  详细解决方案

小弟我想知道在spring aop的环绕通知得到HttpServletReponse对象

热度:17   发布时间:2016-04-17 10:27:50.0
我想知道在spring aop的环绕通知得到HttpServletReponse对象
Java code
@Component@Aspectpublic class SpringAspect {    @Around("execution(* cn.luna.web.controller.*.*(..))")    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {        Method method=((MethodSignature)pjp.getSignature()).getMethod();        //想在这里得到HttpServletRequest request和HttpServletReponse response        System.out.println("进入方法前:"+method);        Object result = pjp.proceed();        System.out.println("退出方法后");        return result;    }}

上面是一个环绕通知,想在doBasicProfiling方法内得到HttpServletRequest和HttpServletReponse对象,想问一下有什么办法,我使用的是spring mvc,我知道如果使用struts1,从拦截方法参数很容易解决问题,使用struts2,从ServletActionContext应该也容易得到,不使用struts,使用一个filter,将HttpServletRequest和HttpServletReponse Set到ThreadLocal<T>里,想用再拿也是一种方法,另外,从拦截的方法都有HttpServletRequest和HttpServletReponse,再从方法的参数取,也是一种方法,但spring mvc的controller方法里不一定都有HttpServletRequest和HttpServletReponse参数。


我试过在切面SpringAspect内使用下面方法注入得到request,但现在得不到HttpServletReponse response,就差这一点需求。想问一下各位有什么高见。
@Autowired(required=false)
private HttpServletRequest request;


------解决方案--------------------
推荐楼主看下,很不错
http://zg770423.blog.163.com/blog/static/13826688820112275259181/
  相关解决方案