简体   繁体   中英

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?

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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