Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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:

Backported to: 4.3.19

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions