SpringBoot Aop不生效

狠扯蛋得一个问题,最近准备对一个查询操作进行aop拦截入缓存,于是写了个测试代码引入了aop

第一步:导入了依赖

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

第二部:编写切面类,注解类

/**
 * @description: 自定义缓存注解
 * @create: 2021-11-17 10:13
 */
@Retention(value = RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface CacheLog {
}
 */
@Aspect
@Component
public class RedisAspect {
    /**
     *注解含义:在添加了@CacheLog注解或者com.xuejf.spring.cloud.service这个包下面得所有类都进行拦截
     */
    @Pointcut("@annotation(com.pro.spring.cloud.util.CacheLog)|| execution(public * com.pro.spring.cloud.service..*.*(..))")
    public void getCacheConfig(){}

    @Around("getCacheConfig()")
    public Object invoke(ProceedingJoinPoint joinPoint){
        Object proceed = null;
        Object[] args = joinPoint.getArgs();
        System.out.println("入参:"+Arrays.asList(args));
        try{
            proceed = joinPoint.proceed();
            System.out.println("出参:"+proceed.toString());
        }catch (Throwable throwable){
            throwable.printStackTrace();
        }
        return proceed;
    }
}

接口类引入注解进行切入

@Override
@CacheLog
public int getAl1(String id) {
    Integer integer = Integer.valueOf(id);
    int out = integer.intValue()*10;
    return out;
}

然后进行调用得时候发现无法切入,网上查了很多,都说是没有导入包,没有导入依赖,但是我看了我得都引入了,然后没找到原因,并且这个切面类修改代码没反应,于是我记起来建这个类得时候用得是Aspect,然后改成得java类,然后我重新建了javaclass类,然后可以切入了,问题就出现在这个Aspect,所以大家乖乖得用java class类就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值