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

Making it easier to replace beans that are auto-configured by SpringBootBatchConfiguration #40040

Open
commonquail opened this issue Mar 20, 2024 · 1 comment
Labels
type: enhancement A general enhancement
Milestone

Comments

@commonquail
Copy link

This is #1655 again, with the catch that BatchConfigurer (BasicBatchConfigurer?) is not available in Spring Boot 3. Therefore, the Spring Boot autoconfigured Spring Batch JobLauncher's TaskExecutor cannot be directly customized at all. Users can only provide an alternative JobLauncher bean, as demonstrated in that issue, or forgo Spring Boot's autoconfiguration entirely.

The practical impact of this does not appear significant. It is evident from inspecting the autoconfiguration that it is aimed at command line runners, where synchronous execution seems reasonable to me. In a web context synchronous execution is possibly an acceptable default (debatable, but all right) but the inability to switch to asynchronous execution is not acceptable, however, the autoconfiguration does not help a web context much at all so opting out of it is a minor issue.

Although I think the executor should be possible to configure I might well argue that the bigger issue is that the Spring Boot reference documentation could be clearer about where the autoconfiguration is useful and where it is preferable to skip it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 20, 2024
@wilkinsona wilkinsona changed the title Spring Boot 3.2: cannot create asynchronous JobLauncher Making it easier to replace beans that are auto-configured by SpringBootBatchConfiguration Mar 22, 2024
@wilkinsona
Copy link
Member

I think we could achieve this by having SpringBootBatchConfiguration override the @Bean methods that are declared in DefaultBatchConfiguration and marking them as @ConditionalOnMissingBean. This would be similar to what we've done for some Spring MVC-related beans:

@Override
@Bean
@ConditionalOnMissingBean(name = DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME)
public LocaleResolver localeResolver() {
if (this.webProperties.getLocaleResolver() == WebProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.webProperties.getLocale());
}
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(this.webProperties.getLocale());
return localeResolver;
}
@Override
@Bean
@ConditionalOnMissingBean(name = DispatcherServlet.THEME_RESOLVER_BEAN_NAME)
@Deprecated(since = "3.0.0", forRemoval = false)
@SuppressWarnings("deprecation")
public org.springframework.web.servlet.ThemeResolver themeResolver() {
return super.themeResolver();
}
@Override
@Bean
@ConditionalOnMissingBean(name = DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME)
public FlashMapManager flashMapManager() {
return super.flashMapManager();
}

@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2024
@wilkinsona wilkinsona added this to the 3.x milestone Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants