当前位置: 代码迷 >> J2EE >> 应用spring aop拦截action记录日志的时候,发现同时拦截了action中的getter,setter方法
  详细解决方案

应用spring aop拦截action记录日志的时候,发现同时拦截了action中的getter,setter方法

热度:193   发布时间:2016-04-21 23:17:58.0
使用spring aop拦截action记录日志的时候,发现同时拦截了action中的getter,setter方法?
如何才能不让aop拦截getter,setter方法?
还是在service层记录日志适合些?

------解决方案--------------------
做一些逻辑排除,类似于这样


@Pointcut("!withincode(@org.junit.Test * demo..*(..))")
    public void notInTestMethod() {}
 
    @Pointcut("getStringFieldAnnotatedWithInjectInTheDemoPackage() && notInTestMethod()")
    public void getStringFieldAnnotatedWithInjectInTheDemoPackageAndNotInTestMethod() {}

------解决方案--------------------
好像没有直接去掉方法的语法,关注一下;

可以换个思路,比如给非getter,setter方法加个前缀或是注解,然后再在Pointcut里过滤
  相关解决方案