【发布时间】:2016-05-25 15:16:44
【问题描述】:
我有一个从 Spring 引导应用程序启动的 Spring Batch 作业,如下所示:
主要:
@SpringBootApplication
@ImportResource("jobApplicationContext.xml")
public class BatchJobRunner {
public static void main(String[] args) {
SpringApplication.run(BatchJobRunner.class, args);
}
}
在我的工作申请环境中,我有以下项目:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:*.properties"/>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<batch:job id="myJob" job-repository="jobRepository">
<batch:split id="main" task-executor="simpleAsyncTaskExecutor" next="step3">
<batch:flow>
<batch:step id="flow1">
<!-- definition -->
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="flow2">
<!-- definition -->
</batch:step>
</batch:flow>
</batch:split>
<batch:step id="step3">
<batch:tasklet ref="someTasklet"/>
</batch:step>
</batch:job>
</beans>
最后,我只是这样运行它:
java -jar my-module.jar
作业开始但是:
-
它不会打印出任何东西。这是我的 log4j.properties:
log4j.rootLogger=INFO, stdout log4j.logger.org.springframework.batch=INFO log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 作业最后挂起。我在 step3 中放了一个 Sys.out.print 并且它确实打印了,但是 spring boot 应用程序一直在运行并且永远不会退出。我还尝试添加
@AfterJob和System.exit(..),但也没有用。
我正在使用 Spring f/w 4.1.8、spring boot 1.2.8 和 spring batch 3.0.6(我无法升级我的 spring-core,因为某些依赖项使用该版本)。
知道我做错了什么吗?
编辑:
看起来 beforeJob 和 afterJob 监听器根本没有触发。
【问题讨论】:
-
它挂了哪一步..你是从数据库还是其他地方读取..
-
@surya 如果您查看我的代码 sn-p,我正在使用内存注册表。但我很确定它不会停滞不前。当我在 Spring XD 中运行它时,我能够运行相同的作业。
标签: java spring spring-boot spring-batch