关闭

spring boot aop

193人阅读 评论(0) 收藏 举报
分类:
1、添加依赖
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2、通过配置方式接入aop
@Aspect
@Configuration
public class CacheAop  {

    @Autowired
    private CacheService cacheService;

    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object twiceAsOld(ProceedingJoinPoint thisJoinPoint){
        System.err.println ("切面执行了。。。。");
        System.out.println("@Before:模拟权限检查...");
        String method = thisJoinPoint.getSignature().getDeclaringTypeName() +
                "." + thisJoinPoint.getSignature().getName();
        System.out.println("@Before:目标方法为:" +
                method);
        String argus = Arrays.toString(thisJoinPoint.getArgs());
        System.out.println("@Before:参数为:" + argus);
        System.out.println("@Before:被织入的目标对象为:" + thisJoinPoint.getTarget());
        try {
            Object result = cacheService.getResult(method,argus,thisJoinPoint);
            return result;
        } catch (Throwable e) {
            e.printStackTrace ();
        }
        return null;
    }


}
http://www.oschina.net/code/snippet_727875_49426#71856

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:33422次
    • 积分:516
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:18篇
    • 译文:0篇
    • 评论:5条
    文章分类
    最新评论