Springboot批处理作业未运行

时间:2019-01-10 08:39:02

标签: spring-boot

我在eclispe中构建了springboot批处理作业。问题是即使启动应用程序也没有任何反应,没有数据写入数据库

下面显示的是我的配置文件

@Configuration

@EnableBatchProcessing
public class BatchConfiguration {

@Autowired
public JobBuilderFactory jobBuilderFactory;

@Autowired
public StepBuilderFactory stepBuilderFactory;

@Autowired
private DataSource datasource;
@Value(value="C:\\Users\\user\\Documents\\json_dump\\NW_*.txt")
private Resource[] resources;

@Bean
public JsonItemReader<Beneficiary> reader() {

   ObjectMapper objectMapper = new ObjectMapper();
   // configure the objectMapper as required
   JacksonJsonObjectReader<Beneficiary> jsonObjectReader = 
            new JacksonJsonObjectReader<>(Beneficiary.class);
   jsonObjectReader.setMapper(objectMapper);

   return new JsonItemReaderBuilder<Beneficiary>()
                 .jsonObjectReader(jsonObjectReader)
                 .name("tradeJsonItemReader")
                 .build();
}
@Bean
public MultiResourceItemReader<Beneficiary> multireader()
{
    MultiResourceItemReader<Beneficiary> multireader=new MultiResourceItemReader<Beneficiary>();
    multireader.setResources(resources);
    multireader.setDelegate(reader());
    return multireader;
}
@Bean
public BeneficiaryProcessor processor()
{
    return new BeneficiaryProcessor();
}
@Bean
public JdbcBatchItemWriter<Beneficiary> writer()
{
    JdbcBatchItemWriter<Beneficiary> writer=new JdbcBatchItemWriter<Beneficiary>();
    writer.setDataSource(datasource);
    writer.setSql("replace into pb (pb.gender,pb.role,pb.BeneficiaryName) values (?,?,?)");
            writer.setItemPreparedStatementSetter(new BeneficiaryPreparedStatementSetter());
    return writer;
}
@Bean
public Step step1()
{return stepBuilderFactory.get("step1").<Beneficiary,Beneficiary>chunk(5).reader(multireader()).processor(processor()).writer(writer()).build();}

@Bean
public Job exportJob()
{
    return jobBuilderFactory.get("importBeneficiaryJob").incrementer(new RunIdIncrementer()).flow(step1()).end().build();
}

这是我的属性文件

 spring.jpa.hibernate.ddl-auto=none
 spring.datasource.url=jdbc:mysql://localhost:3306/agentdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
 spring.datasource.username=root
 spring.datasource.password=root
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 logging.level.=DEBUG

我研究的教程表明可以通过仅启动应用程序来运行该作业。但是,当我启动它时什么也没有发生。也就是说,它启动了,但是作业没有执行。

我正在使用Springboot 2.1.1

0 个答案:

没有答案