Spring Batch 作业不会自动启动

问题描述 投票:0回答:0

我正在使用 Spring Boot v2.7.9、Spring v5.3.25 运行应用程序。在我更改数据源配置之前,我的工作是自动启动的。

@Configuration
@EnableBatchProcessing
@Slf4j
public class BatchConfiguration extends DefaultBatchConfigurer{

@Autowired
private StepBuilderFactory stepBuilderFactory;

private DataSource createbatchDataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            //.addScript("/org/springframework/batch/core/schema-h2.sql")
            .build();
}

@Override
public void setDataSource(DataSource dataSource) {
    super.setDataSource(this.createbatchDataSource());
}
 .
 .
 .
}

现在我在另一个类中有一个数据源配置,但是当我执行 jar 时,作业不执行,只能在 Eclipse 中工作。

@Configuration
@Slf4j
public class DataSourceConfig {

public static boolean isDbOpen = true;

@Bean
@Primary
public DataSource batchDataSource() {
    return
            new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("/org/springframework/batch/core/schema-h2.sql")
            .build();
}

问题是什么?

java spring spring-batch boot
© www.soinside.com 2019 - 2024. All rights reserved.