1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
您已將 Spring AOP 配置為強(qiáng)制創(chuàng)建 CGLIB 代理,即使對于像這樣的接口類型ScheduledExecutorService,也可能通過
@EnableAspectJAutoProxy(proxyTargetClass = true)
只需刪除該proxyTargetClass = true部分或設(shè)置為false,然后您的方面就會(huì)起作用。您不需要任何is(FinalType)切入點(diǎn)指示符,只需編寫類似
@Before("execution(* schedule*(..))")
為了攔截調(diào)度程序方法。
更新:讓我解釋一下為什么對is(FinalType)您沒有幫助以及為什么認(rèn)為它不起作用是錯(cuò)誤的:
再次閱讀錯(cuò)誤消息:
Could not generate CGLIB subclass of class
[class java.util.concurrent.Executors$DelegatedScheduledExecutorService]:
Common causes of this problem include using a final class or a non-visible class;
nested exception is
java.lang.IllegalArgumentException: No visible constructors in class
java.util.concurrent.Executors$DelegatedScheduledExecutorService
“沒有可見的構(gòu)造函數(shù)”并不意味著該類是最終的,它的意思是:沒有可見的構(gòu)造函數(shù)。實(shí)際上,內(nèi)部靜態(tài)類在所在位置Executors.DelegatedScheduledExecutorService是受包保護(hù)的。如果您查看源代碼,您會(huì)看到:java.util.concurrentExecutors
static class DelegatedScheduledExecutorService
extends DelegatedExecutorService
implements ScheduledExecutorService {
private final ScheduledExecutorService e;
DelegatedScheduledExecutorService(ScheduledExecutorService executor) {
super(executor);
e = executor;
}
// (...)
}
看?final這里沒有課。實(shí)際問題是由于 JVM 的限制,CGLIB 無法創(chuàng)建子類:如果不在另一個(gè)包中,則不能將其子類化public。
這就是為什么我告訴你讓 Spring 使用 JDK 動(dòng)態(tài)代理并利用這樣一個(gè)事實(shí),在這種情況下子類化不是必需的,但實(shí)現(xiàn)一個(gè)接口就足夠了。
添加回答
舉報(bào)