AOP拦截器(面向切面编程)

1)AOP拦截器(面向切面编程),主要功能是对业务层的方法调用进行拦截处理,SpringBoot默认情况下并没有配置AOP拦截器。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2)定义AOP程序类,对业务方法进行拦截

/**
 * aop程序类,对业务方法进行拦截,本例使用环绕通知处理
 *
 * @author relax
 * @version 1.0
 * @date 2021/8/24 10:34
 */

@Aspect
@Component
public class ServiceAspect {

    @Around("execution(* com.python.music..service..*.*(..))")
    public Object aroundInvoke(ProceedingJoinPoint point) throws Throwable {
        System.out.println("[***service-before***]执行参数" + Arrays.toString(point.getArgs()));
        //进行具体业务调用
        Object obj = point.proceed(point.getArgs());
        System.out.println("[***service-after***]返回结果" + obj);
        return obj;
    }

}
[***service-before***]执行参数[莉莉安, Window]
爬取莉莉安的音乐数量:1
[***service-after***]返回结果[MusicDO(id=002tnaXt0tJTIV, song= 莉莉安, musician= 宋冬野, createTime=Tue Aug 24 10:47:39 CST 2021, playCount=0, delFlag=0, musicLink= https://isure.stream.qqmusic.qq.com/C400002VoeFn1hzj2v.m4a?guid=7469768631&vkey=534288D3DD93C3DBFC8F89A96DA1DF75621B56C0B03E1510330C853D1C8CD490F09489708FA1328DC8D1FECB4D8A0F33CACC4727F59792ED&uin=&fromtag=66)]
[MusicDO(id=002tnaXt0tJTIV, song= 莉莉安, musician= 宋冬野, createTime=Tue Aug 24 10:47:39 CST 2021, playCount=0, delFlag=0, musicLink= https://isure.stream.qqmusic.qq.com/C400002VoeFn1hzj2v.m4a?guid=7469768631&vkey=534288D3DD93C3DBFC8F89A96DA1DF75621B56C0B03E1510330C853D1C8CD490F09489708FA1328DC8D1FECB4D8A0F33CACC4727F59792ED&uin=&fromtag=66)]

 

AOP拦截器(面向切面编程)

上一篇:安装oracle 10g rac 的一个问题。


下一篇:PolarDB for PostgreSQL 内核解读 :HTAP架构介绍