Maven 未能根据计划运行作业
我将根据计划运行批处理。我使用了计划注释和cron表达式。批处理仅运行一次。没有显示任何错误。我已经为quartz添加了maven依赖项。我没有添加任何XML文件Maven 未能根据计划运行作业,maven,spring-boot,cron,Maven,Spring Boot,Cron,我将根据计划运行批处理。我使用了计划注释和cron表达式。批处理仅运行一次。没有显示任何错误。我已经为quartz添加了maven依赖项。我没有添加任何XML文件 @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,SwaggerConfig.class, WebMvcAutoConfiguration.class,RepositoryRestMvcAutoConfiguration.class
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,SwaggerConfig.class,
WebMvcAutoConfiguration.class,RepositoryRestMvcAutoConfiguration.class })
@EnableScheduling
@ComponentScan
public class BatchApplication {
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(BatchApplication.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext ctx = app.run(args);
System.out.println(ctx.getBean(DataSource.class));
JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
Job addLeaveAllocationJob = ctx.getBean("addLeaveAllocationJob", Job.class);
JobParameters jobParameters = new JobParametersBuilder().addDate("date", new Date())
.toJobParameters();
JobExecution jobExecution = jobLauncher.run(addLeaveAllocationJob, jobParameters);
BatchStatus batchStatus = jobExecution.getStatus();
while(batchStatus.isRunning()){
System.out.println("*** Still Running ************");
Thread.sleep(2000);
}
}
}
我有一个作业类,它是用带有cron表达式的@scheduled注释调度的
@Configuration
@EnableBatchProcessing
@Component
public class LeaveAllocationJobConfiguration {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private EntityManagerFactory entityManagerFactory;
@Bean
public ItemReader<Employee> reader() {
JpaPagingItemReader<Employee> employeeReader = new JpaPagingItemReader<Employee>();
employeeReader.setEntityManagerFactory(entityManagerFactory);
employeeReader.setQueryString("from Employee");
return employeeReader;
}
@Bean
@Scheduled(cron="0 0/1 * 1/1 * ? *")
public Job addLeaveAllocationJob() {
System.out.println("Hello");
return jobs.get("addLeaveAllocationJob").listener(protocolListener()).start(step()).build();
}
@Bean
public Step step() {
// important to be one in this case to commit after every line read
return stepBuilderFactory.get("step").<Employee, EmployeeDTO> chunk(1).reader(reader()).processor(processor())
.writer(writer()).build();
}
/**
* @return
*/
@Bean
public ItemWriter<? super EmployeeDTO> writer() {
return new ItemWriter<EmployeeDTO>() {
@Override
public void write(List<? extends EmployeeDTO> items) throws Exception {
System.out.println("Processing " + items);
}
};
}
@Bean
public ItemProcessor<Employee, EmployeeDTO> processor() {
return new ItemProcessor<Employee, EmployeeDTO>() {
@Override
public EmployeeDTO process(Employee employee) throws Exception {
return new EmployeeDTO(employee);
}
};
}
@Bean
public ProtocolListener protocolListener() {
return new ProtocolListener();
}
}
@配置
@启用批处理
@组成部分
公共类LeaveAllocationJobConfiguration{
@自动连线
私人建筑工地;
@自动连线
私人StepBuilderFactory StepBuilderFactory;
@自动连线
私人实体管理工厂实体管理工厂;
@豆子
公共项目阅读器(){
JpaPagingItemReader employeeReader=新的JpaPagingItemReader();
employeeReader.setEntityManagerFactory(entityManagerFactory);
employeeReader.setQueryString(“来自员工”);
返回员工负责人;
}
@豆子
@已计划(cron=“0/1*1/1*?*”)
公共作业addLeaveAllocationJob(){
System.out.println(“你好”);
返回jobs.get(“addLeaveAllocationJob”).listener(protocolListener()).start(step()).build();
}
@豆子
公共步骤(){
//在这种情况下,重要的是在每一行读取后提交
返回stepBuilderFactory.get(“step”).chunk(1).reader(reader()).processor(processor())
.writer(writer()).build();
}
/**
*@返回
*/
@豆子
PublicItemWriter检查此链接