2

这是主课。现在,我的问题是:

调度程序工作并且每分钟重复一次,但作业仅在应用程序启动时执行(读取器、处理器和写入器仅在启动时执行一次),并且当调度程序在主类中触发时,它无法调用批处理作业。

@EnableMongoAuditing
@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
//@EnableEurekaClient
public class RewardPocApplication extends SpringBootServletInitializer {

    @Autowired
    ApplicationConfig applicationConfig;

    @Autowired
    private JobLauncher jobLauncher;

    @Autowired
    Job job;

    /**
     * @param args Java args
     */
    public static void main(String[] args) {
        SpringApplication.run(RewardPocApplication.class, args);
    }

     @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
             return application.sources(RewardPocApplication .class);
    }

    @Scheduled(cron = "0 */1 * * * ?")
    public void triggerRewardManagementJob() throws Exception {

        JobParameters params = new JobParametersBuilder()
                .addString("readRewardPointsData", String.valueOf(System.currentTimeMillis()))
                .toJobParameters();
        JobExecution execution = jobLauncher.run(job, params);

        System.out.println("Exit Status : " + execution.getStatus());

     }

这是我的 Java 批处理作业代码

   @Configuration
    @EnableScheduling
    @EnableBatchProcessing
    public class ApplicationConfig {

        @Autowired
        private JobBuilderFactory jobBuilderFactory;

        @Autowired
        private StepBuilderFactory stepBuilderFactory;

        @Autowired
        private MongoTemplate mongoTemplate;

        @Autowired
        private MailUtil mailUtil;

        @Autowired
        RewardRepository rewardRepository;




        @Bean
        public Job rewardManagementJob() throws Exception {
            System.out.println("Deepak" + "Job Started");

            return jobBuilderFactory.get("rewardManagementJob")
                    .incrementer(new RunIdIncrementer())
                    .flow(step1())
                    .end()
                    .build();
        }

        @Bean
        public Step step1() throws Exception{

            System.out.println("Deepak" + "Step Started");
            return stepBuilderFactory.get("step1").<RewardEntity, RewardEntity>chunk(10)
                    .reader(reader())
                    .processor(process())
                    .writer(writter())
                    .build();
        }
4

0 回答 0