You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Thanks very much for the sample. It made reproducing the problem straightforward. The problem is that the aspect that honours @Async is lazy and isn't applied. You can work around this by excluding it from lazy initialization:
We don't have any auto-configuration for @EnableAsync so there's no immediately obvious place for us to put this exclude filter in Boot. Hopefully the above work around will help for now. We'll discuss this as a team to see if we can agree on somewhere to configure it in Boot itself.
We're going to make a change in 3.3 so that all infrastructure beans are excluded from lazy initialization by default (#39831). In the meantime, the filter-based workaround above should be used. Thanks for bringing this to our attention.
This project reproduces the problem:
https://github.com/kicktipp/lazyasync
The included test does time out as
@Async
is not working correctly withAdviceMode.ASPECTJ
andlazy-initialization=true
.This works fine usually. To speed up our development server we added this recently
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.@EnableAsync(mode = AdviceMode.PROXY)
@Lazy(false)
to AsyncConfigI don't know if you call it a bug. But at least its a pitfall for developers.
The text was updated successfully, but these errors were encountered: