Spring boot Spring启动升级到2.2后,不会触发Spring批处理作业
我有以下基于xml的批处理配置,但作业没有得到执行。我没有看到任何错误,而提出的应用程序,我怀疑有一个错误的配置,我无法找出。以下是配置: Application.java如下所示:Spring boot Spring启动升级到2.2后,不会触发Spring批处理作业,spring-boot,spring-batch,Spring Boot,Spring Batch,我有以下基于xml的批处理配置,但作业没有得到执行。我没有看到任何错误,而提出的应用程序,我怀疑有一个错误的配置,我无法找出。以下是配置: Application.java如下所示: @SpringBootApplication(exclude= {ValidationAutoConfiguration.class, WebMvcAutoConfiguration.class }) @ImportResource("classpath:/application.xml") @ComponentS
@SpringBootApplication(exclude= {ValidationAutoConfiguration.class, WebMvcAutoConfiguration.class })
@ImportResource("classpath:/application.xml")
@ComponentScan(value = "com.abc.xyz.app.configuration") //retrives dataSource
@EnableScheduling
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
application.xml
<import resource="classpath:/app-batch-context.xml"/>
<import resource="classpath:/job_1.xml"/>
<import resource="classpath:/schdeuler_1.xml"/>
app-batch-context.xml包含以下内容
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="appJobRepository"/>
</bean>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<property name="jobExplorer" ref="jobExplorer"/>
<property name="jobLauncher" ref="jobLauncher"/>
<property name="jobRepository" ref="appJobRepository"/>
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="appJobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="lobHandler" ref="lobHandler"/>
<property name="serializer" ref="xStreamExecutionContextStringSerializer"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="xStreamExecutionContextStringSerializer" class="org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer"/>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
<!-- Wrapper bean to hold the applicationcontext, and make it accessible to all the objects-->
<bean id="appContext" class="com.app.core.AppContextInitializer"></bean>
<bean id="stepListner" class="com.app.core.step.APPStepExceutionListner"></bean>
<bean id="jobListner" class="com.app.core.job.APPJobExecutionListner"></bean>
<!-- abstract base Job, all jobs will extend this Job -->
<batch:job id="APPBaseJob" abstract="true" job-repository="appJobRepository">
<batch:listeners>
<batch:listener ref="jobListner"/>
</batch:listeners>
</batch:job>
<!-- abstract base Job, all the steps will extend this step-->
<batch:step id="abstractStep" abstract = "true">
<batch:listeners>
<batch:listener ref ="stepListner"/>
</batch:listeners>
</batch:step>
job_1.xml
<batch:job id="myTestJob" parent="APPBaseJob">
<batch:step id="myTestPreProcessorStep" next="myTestStopProcessingDecider">
<batch:tasklet ref="myTestPreProcessorTasklet"/>
</batch:step>
<batch:decision id="myTestStopProcessingDecider" decider="stopProcessingDecider">
<batch:next on="CONTINUE" to="myTestFileNameValidatorStep" />
<batch:end on="COMPLETED"/>
</batch:decision>
.
.
.
<batch:step id="myTestCustomInputValidatorStep" next="myTestTransformStep">
<batch:tasklet ref="myTestCustomInputValidatorTasklet"/>
</batch:step>
<batch:step id="myTestTransformStep" parent="abstractStep" next="myTestFileTransferStep">
<batch:tasklet>
<batch:chunk reader="myTestFileItemReader" processor="myTestXmlProcessor" writer="myTestItemWriter"
commit-interval="#{stepExecutionContext.get('APPBATCHCONTEXT').appBatch.toBeProcessedSize}"/>
</batch:tasklet>
</batch:step>
<batch:step id="myTestFileTransferStep" next="myTestPostProcessorStep">
<batch:tasklet ref="myTestFileTransferTasklet"/>
</batch:step>
</batch:job>
<!-- File Reader -->
<bean class="com.app.core.reader.v1.APPJaxbFileEntityReader" id="myFileItemReader" scope="step">
<property name="batchContext" value="#{stepExecutionContext.get('APPBATCHCONTEXT')}"></property>
<property name="packageName" value="com.abc.jaxb.xyz.extract"></property>
</bean>
<!-- File Content Writer-->
<bean class="com.app.core.writer.v1.APPXmlJaxbItemWriter" id="myItemWriter" scope="step">
<property name="batchContext" value="#{stepExecutionContext.get('APPBATCHCONTEXT')}"></property>
<property name="packageName" value="com.abc.jaxb.xyz.extract"></property>
</bean>
<bean id="myXmlProcessor" class="com.abc.app.xyz.customprocessor.XMLDocumentProcessor" scope="step">
<property name="batchContext" value="#{stepExecutionContext.get('APPBATCHCONTEXT')}"></property>
<property name="somePropertyDataService" ref="somePropertyDataService"/>
</bean>
<bean id="myFileTransferTasklet" class="com.abc.xyz.customsender.mySenderTasklet">
<property name="stepSkipDeciders" ref="skipStepDeciders"></property>
<property name="router" ref="myRouter"></property>
</bean>
<bean class="com.abc.xyz.app.customsender.ABCRouter"
id="myRouter"></bean>
.
.
.
调度器具有以下信息:使用自定义jobLauncher,但反过来使用org.springframework.batch.core.launch.jobLauncher来运行作业
<task:scheduler id="myScheduler" pool-size="1"/>
<bean id="myLauncher" class="com.abc.xyz.job.APPJobLauncher">
<property name="jobCode" value="abc"></property>
</bean>
<task:scheduled-tasks scheduler="abcScheduler">
<task:scheduled ref="myLauncher" method="startJob" cron="${abcFreq}"/>
</task:scheduled-tasks>
作业频率将在带有cron表达式***/5***的属性文件中*
请务必让我知道是否有任何指针,我应该检查
Spring boot从1.5.x升级到2.2.x
提前感谢。在Application.java中使用@enablebackprocessing即可
@SpringBootApplication(exclude= {ValidationAutoConfiguration.class, WebMvcAutoConfiguration.class })
@ImportResource("classpath:/application.xml")
@ComponentScan(value = "com.abc.xyz.app.configuration") //retrives dataSource
@EnableScheduling
@EnableBatchProcessing
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
感谢您的回复,但我已经尝试过了,结果出现了一个错误,比如说spring.beans.factory.beancreatitionException:创建名为“scopedTarget.commonTaskExecutor”的bean时出错:作用域“step”对于当前线程不是活动的;如果您想从一个单体引用它,请考虑为这个bean定义一个作用域代理;嵌套异常为java.lang.IllegalStateException:没有可用于步骤范围的上下文持有者。我已经在xml配置中添加了Stepscope bean来解决它,但最终导致IllegalStateException:Failed to execute CommandLineRunner错误。
@SpringBootApplication(exclude= {ValidationAutoConfiguration.class, WebMvcAutoConfiguration.class })
@ImportResource("classpath:/application.xml")
@ComponentScan(value = "com.abc.xyz.app.configuration") //retrives dataSource
@EnableScheduling
@EnableBatchProcessing
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}