Spring Boot 错误未设置数据库类型,使用Meta数据表示:MYSQL,未设置TaskExecutor,默认为同步执行器

ncgqoxb0  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(85)

我在运行spring batch时得到了一个错误,将现有代码从spring Boot 2.7.x迁移到3.1.6:
[16-12-2023 08:18:04.248] [] [] INFO [o.s.b.c.c.annotation.BatchRegistrar]在7 ms内完成Spring Batch基础设施bean配置。[16-12-2023 08:18:08.626] [] [] INFO [o.s.b.c.r.s.JobRepositoryFactoryBean]未设置数据库类型,使用Meta数据指示:MYSQL [16-12-2023 08:18:08.698] [] [] INFO [o.s.b.c.c.a.BatchObservabilityBeanPostProcessor]未找到千分尺观察注册表,默认为ObservationRegistry。NOOP [16-12-2023 08:十八:08.708] [] [] INFO [o.s.b.c.c.a.BatchObservabilityBeanPostProcessor]未找到千分尺观察注册表,默认为ObservationRegistry。NOOP [16-12-2023 08:18:08.712] [] [] INFO [o.s.b.c.l.support.SimpleJobLauncher]未设置TaskExecutor,默认为同步执行器。
下面是我的代码:

@Configuration
public class DataSourceBean {

    @Value("${db.datasource.driver-class-name}")
    private String driverName;

    @Value("${db.datasource.url}")
    private String url;

    @Value("${db.datasource.username}")
    private String userName;

    @Value("${db.datasource.password}")
    private String password;

    @Bean(name="dataSource")
    public DataSource dbDatasource() {
        return DataSourceBuilder.create()
            .driverClassName(driverName)
            .url(url)
            .username(userName)
            .password(password)
            .build();
    }


    @Primary
    @Bean(name = "primaryEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(EntityManagerFactoryBuilder builder) {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("hibernate.hbm2ddl.auto", "update");
        return builder
                .dataSource(dbDatasource())
                .packages("com.gigi.apm.card")
                .persistenceUnit("default")
                .properties(properties)
                .build();
    }
}

@Configuration
@EnableBatchProcessing
@EntityScan(basePackages = {"com.gigi.apm.card"})
@EnableJpaRepositories(entityManagerFactoryRef = "primaryEntityManagerFactory",transactionManagerRef = "batchTransactionManager",
    basePackages="com.gigi.apm.card.batch.repository")
public class ApmBatchConfig {

    @Value("${db.batch.batch-size}")
    private int batchSize;

    @Autowired
    @Qualifier("dataSource")
    public DataSource dataSource;

    @Autowired
    private ApmTransactionRepository repository;

    @Bean
    @StepScope
    public Tasklet deleteApmTransactionTasklet() {
        return new DeleteApmTransactionTasklet(repository,batchSize);
    }

    @Bean(name = "transactionManager")
    @Primary
    public JpaTransactionManager batchTransactionManager(@Qualifier("primaryEntityManagerFactory")
                                                             EntityManagerFactory
                                                                     primaryEntityManagerFactory) {
        return new JpaTransactionManager(primaryEntityManagerFactory);
    }

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

    @Bean("step1")
    public Step deleteTransaction(Tasklet deleteApmTransactionTasklet,
                                   PlatformTransactionManager transactionManager,JobRepository jobRepository) {
        return new StepBuilder("deleteTransaction", jobRepository)
                .allowStartIfComplete(Boolean.TRUE)
                .tasklet(deleteApmTransactionTasklet, transactionManager)
                .build();
    }

}

    
public class DeleteApmTransactionTasklet implements Tasklet {

    private static final Logger LOGGER = LoggerFactory.getLogger(DeleteApmTransactionTasklet.class);
    private static final int THREAD_DELAY = 1000;
    private static final String TRANSACTION_STATUS="DONE";

    // limit the number of records that are being processed at time in DB.
    private int batchSize;

    private final ApmTransactionRepository repository;

    public DeleteApmTransactionTasklet(ApmTransactionRepository repository,int batchSize) {
        this.repository= repository;
        this.batchSize=batchSize;
    }

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        try {
            LOGGER.info("Delete action is started.");
            long count = repository.getCountByStatus(TRANSACTION_STATUS);
            LOGGER.info("Number of transactions to be deleted {}", count);
            while (count > 0) {
                 repository.deleteTrnInBatch(TRANSACTION_STATUS, batchSize);
                 // Delay is in place in order to give DB a time to perform replication
                 // Or any other background activity.
                Thread.sleep(1000);
                count = count - batchSize;
            }
            LOGGER.info("Completed transactions are deleted successfully");
        } catch (DataAccessException exception) {
            LOGGER.error("Transactions are not deleted successfully because of error {}", exception);
            return RepeatStatus.CONTINUABLE;
        }
        return RepeatStatus.FINISHED;
    }
}

@Repository
public interface ApmTransactionRepository extends JpaRepository<ApmTransaction, String> {

}

@SpringBootApplication
public class ApmBatchApplication {
    public static void main(String[] args) {
        System.exit(SpringApplication.exit(SpringApplication.run(DecoupledBatchApplication.class, args)));
    }
}

字符串
我正在努力解决这个问题,有人能帮帮我吗?

6tdlim6h

6tdlim6h1#

这些不是错误,而是有关默认配置参数的信息性日志消息。

相关问题