Springboot配置aop

z在pom文件中添加aop的依赖

    <dependency>  
            <groupId>org.springframework.bootgroupId>  
            <artifactId>spring-boot-starter-aopartifactId>  
        dependency>  

在自定义的切面上添加注解@Aspect

@Aspect//描述一个切面类,定义切面类的时候需要打上这个注解
@Component
public class SpringAop {
    Logger logg=Logger.getLogger(getClass());
    @Pointcut("execution(* com.turing.controller.*.*(..))")
    public void qieru(){

    }
    @Around("qieru()")
    public void huanrao(ProceedingJoinPoint poin){
        System.out.println("环绕通知"+logg.getClass().getName());
        poin.proceed();
    }
    @Before("qieru()")
    public void qianzhi(){
        System.out.println("前置通知");
    }
    @After("qieru()")
    public void houzhi(){
        System.out.println("后置通知");
    }

    @AfterReturning("qieru()")
    public void qianzhifanhui(){
        System.out.println("后置返回 ");
    }
    @AfterThrowing("qieru()")
    public void qianzhiYichang(){
        System.out.println("后置异常");
    }

}

你可能感兴趣的:(springboot,aop,springboot2)