Spring Batch disable Spring Boot AutoConfiguration for specific jobs

坚强是说给别人听的谎言 提交于 2021-02-04 21:52:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!