Spring Batch 为特定作业禁用 Spring Boot AutoConfiguration [英] Spring Batch disable Spring Boot AutoConfiguration for specific jobs

查看:46
本文介绍了Spring Batch 为特定作业禁用 Spring Boot AutoConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Spring Batch 应用程序有多个作业,但只有一个作业使用某些特定的 Spring Boot 自动配置功能:

I have multiple jobs for my Spring Batch application, but only a single job uses some specific Spring Boot auto configuration features:

  • 使用 spring-data-jpa 自动配置的作业,为业务事务配置数据库(不适用于 Spring Batch 管理)
  • 根本不使用数据库的作业

我将这两个工作打包在同一个单元中,因为从业务角度来看这很有意义.两个作业将协同工作,一个作业的输出将成为另一个作业的输入.

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?

推荐答案

我刚刚尝试使用配置文件,但已禁用特定配置文件的自动配置.我对这个解决方案很满意,但我想知道是否还有其他解决方案?

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?

这类似于尝试延迟加载特定于给定作业的 bean:如何将 @Lazy 之类的东西应用到 Spring Batch?.虽然 Spring 配置文件功能可能会解决您的问题,但我相信它正在解决以整体方式打包所有作业的根本问题.

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:

  • 独立的生命周期管理(错误、功能等)
  • 灵活部署
  • 单独的日志
  • 单独的配置(如当前问题)
  • 更轻松/更好的可扩展性

以及让一件事做一件事并把它做好的所有充分理由.

And all the good reasons to make one thing do one thing and do it well.

这篇关于Spring Batch 为特定作业禁用 Spring Boot AutoConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆