簡體   English   中英

為什么 Spring 啟動 AspectJ 錯過觸發有時只是

[英]why Spring boot AspectJ missed to trigger sometimes only

我有 Spring 啟動應用程序AspectJ配置為在一項服務返回數據后異步工作,但這有時無法觸發,只有沒有錯誤日志沒有警告,這可以隨時發生,如果我錯過了任何 conf,請告訴我?

應用代碼

@SpringBootApplication
@EnableAspectJAutoProxy
@EnableAsync
public class TitlesCompareUtilityApplication {

    public static void main(String[] args) {
        SpringApplication.run(TitlesCompareUtilityApplication.class, args);
    }

}

方面代碼

@Aspect
@Component
public class DistributedLoggingAspect {

    private static Logger log = LoggerFactory.getLogger(DistributedLoggingAspect.class);

    @Async
    @AfterReturning("execution(* com.mycomp.repo.TyRepository.findById(..))")
    public void logAfterReturn(JoinPoint joinPoint) {
        int id = (int) joinPoint.getArgs()[0];
        log.info("logAfterReturn() is running! id:{}", id);
    }
}

由於技術原因,我發現它極不可能,甚至幾乎不可能,有時會錯過建議執行,因為當調用公共 Spring bean/組件方法並且存在 AOP 代理時,該代理將攔截方法調用,除非您執行 self -invocation(類內部方法調用)。 建議是在同一個線程還是異步線程中執行(如果可能的話),應該無關緊要。

相反,由於您的應用程序的異步特性,日志條目沒有按照您期望的順序出現,或者在高負載情況下您的記錄器緩沖區溢出(取決於您的配置)並且日志消息丟失的可能性更大在它們被寫入之前。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM