Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: AsyncConfigurer causes dependencies to be created early [SPR-16945] #21484

spring-issuemaster opened this issue Jun 15, 2018 · 0 comments


Copy link

@spring-issuemaster spring-issuemaster commented Jun 15, 2018

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:

Issue Links:

  • #21483 Doc: ThreadPoolTaskExecutor's defaults vs setting queueCapacity for common pool scenarios
  • #21559 Lazily retrieve delegate beans in AsyncConfigurer and CachingConfigurer

Backported to: 4.3.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.