-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Rethink DefaultBatchConfiguration and/or update its doc #4650
Comments
Case in point: I need to use Lines 231 to 247 in 425134c
|
Thank you for sharing your thoughts! I wish we had such great feedback when we worked on #3942 (which I recommend you to check if you want to understand the rationale behind the design choices in v5).
The idea of defining default infrastructure beans in a base class is not new, it is actually similar to several classes with same purpose across the portfolio (like AbstractDispatcherServletInitializer in Spring MVC and AbstractSecurityWebApplicationInitializer in Spring Security). Composition over Inheritance really applies to business services in application code to make them swappable. In this context, we are actually writing some configuration code that we inherit from a base class and override if needed). That said, you can still
Factory beans should not be leaked in the API, otherwise this would be a design mistake IMHO. They are nothing more than nice to have components to ease the configuration of infrastructure beans. As a batch user, I should be able to define an infrastructure bean (a
That's a fair point. I always recommend to separate infrastructure beans from business beans. A good example is the hello world tutorial, where infrastructure beans are defined in a separate class and imported in the job configuration class. The example you referred to can be refactored as such too, but one could argue that it is ok to inherit infrastructure beans from a base class (which is considered a separate class).
I understand and agree. This is a known limitation, I will add a comment on spring-projects/spring-boot#40040 to mention that this is currently missing in Spring Boot. Currently, I can define a datasource and it will be picked up and set on the job repository (ie I don't have to redefine the job repository). In the same way, I should be able to define a task executor to use in the job launcher without having to redefine a job launcher. Hopefully I answered all your questions. |
This is a valid issue. Similar to the |
Hi, I think
DefaultBatchConfiguration
has some issues that need to be addressed:The documentation suggests that it should be extended
Quote:
DefaultBatchConfiguration
. But following Composition over Inheritance, you would rather want to import it.DefaultBatchConfiguration
should probably be to override e. g.getTaskExecutor()
, allowing you to customize the Batch infrastructure. But then again, following Composition over Inheritance, it might be better to let the user provide a factory bean and/or a customizer.JobRepositoryFactoryBean
, these are hard coded and can neither be changed nor customized by the user.DefaultBatchConfiguration
. This mixes two things that, IMO, should not be mixed: Batch infrastructure configuration and job configurations. What if you want to have multiple classes that define jobs, would you then extendDefaultBatchConfiguration
multiple times? No, because if you do that, from which class will the beans be taken? Imagine overridinggetTaskExecutor()
in multiple subclasses: only one will win. So as a user, you most likely want to subclassDefaultBatchConfiguration
at most once and put jobs into separate configs. Not everyone might realize this. Therefore, I think the doc shouldn't suggest mixing job config with infrastructure.It makes auto configuration difficult for Spring Boot
Even if customizable bean factories were provided, it would still not work well with Spring Boot AutoConfiguration where users expect beans to be replaceable. See spring-projects/spring-boot#40040
If the suggested solution works, this point might be invalid. Still, maybe it's something to be considered.
I'm interested in reading your thoughts. When I find the time, I would also like to provide suggestions. Unfortunately, I can't right now.
The text was updated successfully, but these errors were encountered: