问题
I have multiple jobs for my Spring Batch application, but only a single job uses some specific Spring Boot auto configuration features:
- a job that uses spring-data-jpa auto configuration, to configure a database for business transactions (not for Spring Batch management)
- a job that does not use the database at all
I have packaged both jobs in the same unit because it makes sense from business perspective. Both jobs will work together and the output of one job will be the input of the other job.
Is it possible to disable database specific auto configuration when I run the second job?
回答1:
I just tried using profiles and I have disabled the autoconfiguration for a specific profile. I am pretty happy with this solution but I wonder if there are other solutions?
This is similar to trying to lazy load beans specific to a given job: How to apply something like @Lazy to Spring Batch?. While the Spring profiles feature may fix your issue, I believe it is working around the root issue which is packaging all jobs in a monolithic way.
I would package each job separately and this problem (and many others) disappears by design. There are several advantages to this approach:
- Independent lifecyle management (bugs, features, etc)
- Flexible deployment
- Separate logs
- Separate configurations (as in the current issue)
- Easier/Better scalability
And all the good reasons to make one thing do one thing and do it well.
来源:https://stackoverflow.com/questions/62210349/spring-batch-disable-spring-boot-autoconfiguration-for-specific-jobs