简体   繁体   English

为什么 Spring 启动 AspectJ 错过触发有时只是

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

I have Spring boot application AspectJ is configured to work async after one service returned data but this fails to triggers sometime only there is no error logs no warning, can this happen any time, please let me know if I have missed any conf?我有 Spring 启动应用程序AspectJ配置为在一项服务返回数据后异步工作,但这有时无法触发,只有没有错误日志没有警告,这可以随时发生,如果我错过了任何 conf,请告诉我?

Application code应用代码

@SpringBootApplication
@EnableAspectJAutoProxy
@EnableAsync
public class TitlesCompareUtilityApplication {

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

}

Aspect code方面代码

@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);
    }
}

For technical reasons I find it highly unlikely, even next to impossible, that advice execution would sometimes be missed because when a public Spring bean/component method is called and an AOP proxy exists, this proxy will intercept the method call, unless you perform self-invocation (class-internal method call).由于技术原因,我发现它极不可能,甚至几乎不可能,有时会错过建议执行,因为当调用公共 Spring bean/组件方法并且存在 AOP 代理时,该代理将拦截方法调用,除非您执行 self -invocation(类内部方法调用)。 Whether the advice is executed in the same or an asynchronous thread (if that is even possible), should not matter.建议是在同一个线程还是异步线程中执行(如果可能的话),应该无关紧要。

Instead, it is much more likely that due to the asynchronous nature of your application the log entries do not appear in the order you expect or that in a high-load scenario your logger buffer overruns (depending on your configuration) and log messages get lost before they can be written.相反,由于您的应用程序的异步特性,日志条目没有按照您期望的顺序出现,或者在高负载情况下您的记录器缓冲区溢出(取决于您的配置)并且日志消息丢失的可能性更大在它们被写入之前。

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

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