spring-boot
spring-boot copied to clipboard
@Async annotations are not working with AdviceMode.ASPECTJ and lazy-initialization=true
This project reproduces the problem:
https://github.com/kicktipp/lazyasync
The included test does time out as @Async is not working correctly with AdviceMode.ASPECTJ and lazy-initialization=true .
@Configuration
@EnableAsync(mode = AdviceMode.ASPECTJ)
public class AsyncConfig {
}
This works fine usually. To speed up our development server we added this recently
spring.main.lazy-initialization=true
With lazy-initialization set to true, the ThreadPoolTaskExecutor is not configured, therefore all @Async methods are called synchronously which can lead to subtle bugs with @Transactional annotations which are difficult to understand in development mode.
- Test runs fine with
@EnableAsync(mode = AdviceMode.PROXY) - Test still fails if I add
@Lazy(false)to AsyncConfig
I don't know if you call it a bug. But at least its a pitfall for developers.