annotation:
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RedissonLock {
String key();
int timeout() default 60;
}
The method lockTest() will not be intercepted by AOP :
@Component
public class LockTest1 {
@Autowired
private LockTest2 lockTest2;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
public String key = "test";
@RedissonLock(key = "#root.targetClass.getName()")
@Scheduled(cron = "1/10 * * * * ? ")
public void lockTest() throws InterruptedException {
System.out.println("Scheduled task:" + dateFormat.format(new Date()));
}
}
@Component
public class LockTest2 {
@Autowired
private LockTest1 lockTest1;
public void callLockTest1() throws InterruptedException {
lockTest1.lockTest();
}
}
The class LockTest1 is not represented by cglib in org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor#postProcessAfterInitialization
See demo: https://github.com/G-XD/aop-failure
Comment From: wilkinsona
Thanks for the sample. The loss of the proxy is a side-effect of the steps that Spring Framework has to break the dependency cycle. You should either restructure your application to avoid the cycle, or "break" it yourself using @Lazy on the injection point or injecting an ObjectProvider.