-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Auto-configure a bootstrapExecutor bean to be used by Framework's background bean initialization #39791
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
Comments
Hi @wilkinsona I'd like to contribute to the issue. However, I'm facing some issues. Line 17 in af0353d
@Bean(bootstrap=BACKGROUND) feature is introduced in spring framework 6.2.0. I tried to change the springboot's dependency to the spring framework to springFrameworkVersion=6.2.0-SNAPSHOT but got the following errors:
Is the current springboot version not ready for spring framework 6.2.0 yet? If so, should I develop this enhancement in spring framework? |
Thanks for taking a look, @ballista01. We won't be able to work on this issue until we've started developing Spring Boot 3.4 and have upgraded to a Spring Framework 6.2 milestone or snapshot. This won't happen until some time after Spring Boot 3.3's release in May. |
I’m interested in this issue. May I ask if I can contribute to it? |
Thanks for the offer, @YongGoose, but I'm not sure we know exactly how to implement this yet. Reading spring-projects/spring-framework#13410 (comment) again, there's the possibility of aliasing the application task executor to |
I understand. ps. Additionally, there is another issue I am interested in. Would it be possible for me to contribute to this issue? |
I think that one probably needs some design work too, unfortunately. Reading through the comments there still seems to be quite a bit that's undecided. |
To tackle this, we could add a @Configuration(proxyBeanMethods = false)
static class BootstrapExecutorConfiguration {
private static final String BOOTSTRAP_EXECUTOR_NAME = "bootstrapExecutor";
@Bean
static BeanFactoryPostProcessor bootstrapExecutorAliasPostProcessor() {
return (beanFactory) -> {
boolean hasBootstrapExecutor = beanFactory.containsBeanDefinition(BOOTSTRAP_EXECUTOR_NAME);
boolean hasApplicationTaskExecutor = beanFactory.containsBeanDefinition(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME);
if (!hasBootstrapExecutor && hasApplicationTaskExecutor) {
beanFactory.registerAlias(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, BOOTSTRAP_EXECUTOR_NAME);
}
};
}
} this would alias WDYT? |
Or, without an alias but better for our configuration report: @Configuration(proxyBeanMethods = false)
@ConditionalOnMissingBean(name = "bootstrapExecutor")
@ConditionalOnBean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
static class BootstrapExecutorConfiguration {
@Bean("bootstrapExecutor")
Executor bootstrapExecutor(@Qualifier(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME) Executor applicationTaskExecutor) {
return applicationTaskExecutor;
}
} |
@wilkinsona @mhalbritter Defining it as a If there are no strong objections, I’d like to go ahead and try implementing it. What do you think? |
There is an important distinction between aliasing a bean and explicitly declaring a new bean. When you declare a bean using: @Bean("bootstrapExecutor")
Executor bootstrapExecutor(
@Qualifier(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME) Executor applicationTaskExecutor) {
return applicationTaskExecutor;
} The The second issue is that The third issue is that the init/shutdown operations will be invoked twice, once for
Using the The worse scenario, if the property This BFPP registers the alias @Bean
static BeanFactoryPostProcessor bootstrapExecutorAliasBeanFactoryPostProcessor() {
return (beanFactory) -> {
if (beanFactory.containsBean("applicationTaskExecutor") && !beanFactory.containsBean("bootstrapExecutor")) {
beanFactory.registerAlias("applicationTaskExecutor", "bootstrapExecutor");
}
};
} Javadoc of containsBean
|
@YongGoose i prefer the alias approach, too. Thanks @nosan for your investigation. Let's hold off the implementation for now, i want to talk to the team about it. |
We discussed this today and we'd like to take #39791 (comment). Moritz has this on a branch so we should be able to merge that soon. |
See spring-projects/spring-framework#13410 (comment)
The text was updated successfully, but these errors were encountered: