第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

AspectJ within(is(FinalType)) 錯(cuò)過了

AspectJ within(is(FinalType)) 錯(cuò)過了

Qyouu 2023-04-13 10:48:44
我正在使用 aspectJ 1.8.10。在我的代碼中,我有一個(gè)帶有 ScheduledExecutorService 的 bean:@Beanpublic ScheduledExecutorService backgroundTaskExecutor() {    return Executors.newSingleThreadScheduledExecutor();}當(dāng) bean 實(shí)例化時(shí),代理類拋出:.AopConfigException: 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我知道,ScheduledExecutorService 沒有構(gòu)造函數(shù)是根本原因。但是我需要配置方面的切入點(diǎn)以排除 FinalType 類。像這樣:@Before("!within(is(FinalType)) && execution(* your_method_name(..)) ")但是,正如我提到的,aspectJ 版本 1.8.10 無法識別 is(..) 語法。(Intellij IDEA 警告 Cannot resolve symbol 'is')。應(yīng)用程序啟動(dòng)時(shí)沒有 AOP 問題,但失敗了java.lang.IllegalArgumentException: No visible constructors in class java.util.concurrent.Executors$DelegatedScheduledExecutorService我做錯(cuò)了什么?aspectj > 1.8.4 有什么變化嗎?(是(..)語法)
查看完整描述

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è)接口就足夠了。


查看完整回答
反對 回復(fù) 2023-04-13
  • 1 回答
  • 0 關(guān)注
  • 226 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號