-
Notifications
You must be signed in to change notification settings - Fork 41k
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
AsyncTaskExecutor beans not created if any bean of type Executor is present #44659
Comments
I've attached a sample project which reproduced the issue. If you run it, you'll see it fails to start due to a missing AsyncTaskExecutor bean. If you comment out the |
It should only back off for My proposal: https://github.com/spring-projects/spring-boot/compare/main...quaff:patch-137?expand=1 |
TaskExecutor will back off for custom Executor before this commit, now it only back off for custom TaskExecutor. Fix spring-projectsGH-44659 Signed-off-by: Yanming Zhou <[email protected]>
TaskExecutor will back off for custom Executor before this commit, now it only back off for custom TaskExecutor. Fix spring-projectsGH-44659 Signed-off-by: Yanming Zhou <[email protected]>
Or It make sense since |
I disagree with that and this bit of the auto-configuration is a bit tricky, I reckon. This is due to the bridge we had before the executor abstraction was available in the JDK. The condition on |
@quaff ScheduledExecutorService was just an example. Any bean of type Executor will cause an app to fail startup if they need the AsyncTaskExecutor.
@snicoll We've found the opposite. Users define a bean for other purposes but expect to still use the AsyncTaskExecutor for other tasks. |
In this case, you can use @Bean(defaultCandidate = false)
@Qualifier("myexecutor")
public ScheduledExecutorService executorService() {
return Executors.newSingleThreadScheduledExecutor();
} This way, you will have both the auto-configured |
There appears to be a bug in TaskExecutorConfiguration when creating an AsyncTaskExecutor bean, the condition is:
instead of on AsyncTaskExecutor.
The result is, if an app creates a bean of type Executor (such as a ScheduledExecutorService), this results in Spring’s default AsyncTaskExecutor beans to not be created. The application will fail to start because of the missing beans.
This is for apps trying to use the bean generated for the configuration with the Task Execution and Scheduling feature. If an app creates a bean of type Executor, the above bean never gets created.
The text was updated successfully, but these errors were encountered: