-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Petr Stuchlik opened SPR-16945 and commented
JavaDoc for @EnableAsync
suggests implementing AsyncConfigurer to customize AsyncUncaughtExceptionHandler. This works fine and one would typically extend AsyncConfigurerSupport in his configuration class. This can, however, lead to a rather nasty issue (or difficult-to-debug at least) when also expressing a direct bean dependency in this configuration class.
The issue is that this dependency causes the bean (and all its dependencies) to be created very early - at the time when BeanPostProcessors are registered. That prevents these beans to be processed (e.g. by AspectJ processors).
This happens because ProxyAsyncConfiguration finds the AsyncConfigurer and causes this config to be created along with its dependencies, when other processors are not available yet.
For workaround, one can often annotate the bean dependency in the config as @Lazy
.
After lengthy investigation why my beans are not CGLIB-proxied I've found this cause. Having learned how the ProxyAsyncConfiguration is bootstrapped I no longer find this behavior surprising. But if this was stated somewhere in the JavaDoc at least I'd have more hair on my head at this moment.
You can see the referenced PoC on GitHub for more details.
Affects: 4.3.18, 5.0.7
Reference URL: https://github.com/stuchl4n3k/spring-async-configurer-issue
Issue Links:
- Doc: ThreadPoolTaskExecutor's defaults vs setting queueCapacity for common pool scenarios [SPR-16944] #21483 Doc: ThreadPoolTaskExecutor's defaults vs setting queueCapacity for common pool scenarios
- Lazily retrieve delegate beans in AsyncConfigurer and CachingConfigurer [SPR-17021] #21559 Lazily retrieve delegate beans in AsyncConfigurer and CachingConfigurer
Backported to: 4.3.19