问题描述
我有一个符合 JSR-352 的简单 Spring Batch 应用程序.
I have a simple Spring Batch application complying with JSR-352.
我需要将它部署为 Spring Cloud Data Flow 服务器上的托管任务.据我所知 - 为了能够将其部署为任务,我需要将此应用程序转换为 Spring Boot 应用程序.
I need to deploy this as a managed Task on Spring Cloud Data Flow server. As far as I know - to be able to deploy this as a Task I need to convert this application as a Spring Boot app.
我尝试添加 Spring Boot 依赖项和 Main 类,但是当我启动应用程序时它没有运行批处理作业.
I have tried to add Spring Boot dependencies and Main class however it is not running the Batch job when I start the app.
主类
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableBatchProcessing
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
批处理文件创建于
META-INF/batch-jobs/myjob.xml
当我在主类中使用 JobOperator 来启动作业(没有 Spring Boot)时,它可以工作.
It works when I use JobOperator in the main class to start the job (without Spring Boot).
将它作为 Spring Boot 应用程序运行我缺少什么?
What am I missing to run this as a Spring Boot app?
推荐答案
您缺少 @EnableTask
注释.这样,您的批处理作业将作为短期应用程序运行.换句话说,只要您的 XML 中的业务逻辑需要运行,应用程序就会运行,并且它会优雅地关闭和释放资源.
You're missing @EnableTask
annotation. With that, your batch-job will be run as a short-lived application. In other words, the application will run as long as the business logic in your XML needs to run, and it will gracefully shut down and free-up resources.
请克隆并试用 Spring Cloud 任务示例 [参见:BatchJobApplication
].所有这些都应该在 SCDF 中按原样工作.
Please clone and try out the Spring Cloud Task samples [see: BatchJobApplication
]. All of them should work as-is in SCDF as well.
这篇关于在 Spring Boot 上运行 Spring Batch (JSR-352) 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!