未启动Spring批处理作业

kpbwa7wx  于 2023-02-28  发布在  Spring
关注(0)|答案(2)|浏览(139)

'我刚刚开始使用spring batch。我已经完成了spring batch的所有配置。但是作业没有启动。相反,tomcat服务器正在启动。以下是我的配置

@Bean
public FlatFileItemReader<CustomerDetailsDTO> customerCsvFileReader(){
   return  new FlatFileItemReaderBuilder<CustomerDetailsDTO>()
             .name("customerCsvFileReader")
             .delimited()
             .names(JobUtils.CREATE_CUSTOMER_DTO_FIELDS)
             .linesToSkip(1)      //skip the header
             .fieldSetMapper(new CustomerDetailsDTOMapper())
             .targetType(CustomerDetailsDTO.class)
             .resource(new ClassPathResource("cust_data.csv"))
             .build();

 }


    @Bean
    public Job sampleJob(JobRepository jobRepository, Step sampleStep) {
        return new JobBuilder("sampleJob", jobRepository)
                .incrementer(new RunIdIncrementer())
                .start(sampleStep)
                .build();
    }

@Bean
public Step sampleStep(JobRepository jobRepository, PlatformTransactionManager transactionManager,ItemWriter<CustomerDetailsDTO> restItemWriter) {
    return new StepBuilder("sampleStep", jobRepository)
            .<CustomerDetailsDTO, CustomerDetailsDTO>chunk(1, transactionManager)
            .reader(customerCsvFileReader())
            .writer(restItemWriter)
            .build();
}`

但是作业根本没有启动,我在writer中使用的是RestTemplate,所以我包含了spring-boot-starter-web依赖项,我哪里出错了?
以下是日志

2023-02-28T00:55:45.866+05:30  INFO 924 --- [           main] o.s.b.c.c.annotation.BatchRegistrar      : Finished Spring Batch infrastructure beans configuration in 16 ms.
2023-02-28T00:55:47.689+05:30  INFO 924 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-02-28T00:55:47.721+05:30  INFO 924 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-02-28T00:55:47.722+05:30  INFO 924 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-02-28T00:55:48.381+05:30  INFO 924 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-02-28T00:55:48.384+05:30  INFO 924 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3483 ms
2023-02-28T00:55:48.701+05:30  INFO 924 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-02-28T00:55:49.079+05:30  INFO 924 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:4bd9ced2-4ff8-4416-9e0d-0ec290622c63 user=SA
2023-02-28T00:55:49.082+05:30  INFO 924 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-02-28T00:55:49.096+05:30  INFO 924 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: H2
2023-02-28T00:55:49.206+05:30  INFO 924 --- [           main] .c.a.BatchObservabilityBeanPostProcessor : No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
2023-02-28T00:55:49.217+05:30  INFO 924 --- [           main] .c.a.BatchObservabilityBeanPostProcessor : No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
2023-02-28T00:55:49.220+05:30  INFO 924 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2023-02-28T00:55:49.773+05:30  INFO 924 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-02-28T00:55:49.784+05:30  INFO 924 --- [           main] r2sSpringBatchStarterTemplateApplication : Started Br2sSpringBatchStarterTemplateApplication in 5.743 seconds (process running for 6.844)

我是这个 Spring 批次的新手,我希望作业能运行

2lpgd968

2lpgd9681#

如果你使用的是SpringBoot 3,你需要禁用@EnableBatchProcessing,这在this问题中已经提到过

hsvhsicv

hsvhsicv2#

1.应使用@Configuration注解对包含批处理相关Bean的类进行注解
1.在配置中考虑@EnableBatchProcessing注解。
1.还要检查您的应用程序属性中是否有(实际上默认情况下是启用的,但无论如何):

spring:
  batch:
    job:
      enabled: true

相关问题