简体   繁体   English

@Before AOP 不会触发带有 @Cacheable 注释的方法

[英]@Before AOP not triggering to method with @Cacheable annotation

I have created an Aspect that will count my service invocation, it works like a charm for all methods except one method with @Cacheable annotation.我创建了一个方面来计算我的服务调用,它对所有方法都@Cacheable除了带有@Cacheable注释的一种方法。 I thought the problem is because I was using @Around advice but after changing it to @Before , same issue persists.我认为这个问题是因为我用@Around建议,但改变后@Before ,同样的问题仍然存在。 Any workaround?任何解决方法?

Here's my advice method.这是我的建议方法。

@Autowired
private CounterService counterService;

@Before("execution(* DepartmentService.*(..))")
public void increment(JoinPoint joinPoint) throws Throwable {
counterService.increment(joinPoint.getSignature().toShortString());
}

Here's the only method that is not working in Service class.这是在 Service 类中不起作用的唯一方法。

@Override
@Cacheable(value = "departments", key = "#id")
public Department findOne(Long id) {
return departmentRepository.findOne(id);
}

Cacheable 已经在方法周围注入了一个建议,这使得不会调用实际方法,因此不会调用您的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM