layout:
title: 12-SpringBoot-AOP
date: 2017-02-12
updated: 2017-02-12
tags:
categories: SpringBoot实战与原理分析
permalink:
thumbnail:
toc: true
comment: true
notag: false
top: false
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
package com.clsaa.edu.springboot;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
/**
* Created by Egg on 2017/2/26.
*/
@Aspect
@Component
public class LogAspect {
@Before("execution(* com.clsaa.edu.springboot.dao..*.*(..))")
public void log(){
System.out.println("method log done");
}
}
package com.clsaa.edu.springboot;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.Arrays;
/**
* Created by Egg on 2017/2/26.
*/
@Aspect
@Component
public class LogAspect {
@Before("execution(* com.clsaa.edu.springboot.dao..*.*(..))")
public void log(){
System.out.println("before method log done");
}
@After("execution(* com.clsaa.edu.springboot.dao..*.*(..))")
public void logAfter(JoinPoint point){
System.out.println("after method log done " + point.getTarget().getClass() + point.getSignature().getName() +Arrays.toString(point.getArgs()));
}
}