如何解决spring boot @Aspect 不生效的问题?

这个是我的自定义注解类


@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EncryptDb {
}

我的pom 依赖

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

我的注解处理器

@Aspect
@Component
public class EncryptionAspect {

    @Pointcut("@annotation(com.dxjr.finance.fht.managed.common.annotations.EncryptDb)")
    public void encryptDbPointcut() {

    }

    @Pointcut("@annotation(com.dxjr.finance.fht.managed.common.annotations.DecryptDb)")
    public void decryptDbPointcut() {

    }

    @Around("@annotation(encryptDb) && execution(public void * (String)) ")
    public Object encryptDbrypt(ProceedingJoinPoint p, EncryptDb encryptDb) throws Throwable {
        Object[] args = p.getArgs();
        if (args != null && args.length == 1 && StringUtils.isNotEmpty(String.valueOf(args[0]))) {
            return p.proceed(new Object[]{Sm2Utils.encryptDb((String) args[0])});
        } else {
            return p.proceed();
        }
    }

    @Around("@annotation(decryptDb) && execution(public String * (..))")
    public String decryptValue(ProceedingJoinPoint p, DecryptDb decryptDb) throws Throwable {
        String encrypted = (String) p.proceed();
        return StringUtils.isBlank(encrypted) ? encrypted : Sm2Utils.decryptDb(encrypted);
    }
}
阅读 3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题