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

ncgqoxb0  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(206)

我在运行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,默认为同步执行器。
下面是我的代码:

  1. @Configuration
  2. public class DataSourceBean {
  3. @Value("${db.datasource.driver-class-name}")
  4. private String driverName;
  5. @Value("${db.datasource.url}")
  6. private String url;
  7. @Value("${db.datasource.username}")
  8. private String userName;
  9. @Value("${db.datasource.password}")
  10. private String password;
  11. @Bean(name="dataSource")
  12. public DataSource dbDatasource() {
  13. return DataSourceBuilder.create()
  14. .driverClassName(driverName)
  15. .url(url)
  16. .username(userName)
  17. .password(password)
  18. .build();
  19. }
  20. @Primary
  21. @Bean(name = "primaryEntityManagerFactory")
  22. public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(EntityManagerFactoryBuilder builder) {
  23. Map<String, Object> properties = new HashMap<String, Object>();
  24. properties.put("hibernate.hbm2ddl.auto", "update");
  25. return builder
  26. .dataSource(dbDatasource())
  27. .packages("com.gigi.apm.card")
  28. .persistenceUnit("default")
  29. .properties(properties)
  30. .build();
  31. }
  32. }
  33. @Configuration
  34. @EnableBatchProcessing
  35. @EntityScan(basePackages = {"com.gigi.apm.card"})
  36. @EnableJpaRepositories(entityManagerFactoryRef = "primaryEntityManagerFactory",transactionManagerRef = "batchTransactionManager",
  37. basePackages="com.gigi.apm.card.batch.repository")
  38. public class ApmBatchConfig {
  39. @Value("${db.batch.batch-size}")
  40. private int batchSize;
  41. @Autowired
  42. @Qualifier("dataSource")
  43. public DataSource dataSource;
  44. @Autowired
  45. private ApmTransactionRepository repository;
  46. @Bean
  47. @StepScope
  48. public Tasklet deleteApmTransactionTasklet() {
  49. return new DeleteApmTransactionTasklet(repository,batchSize);
  50. }
  51. @Bean(name = "transactionManager")
  52. @Primary
  53. public JpaTransactionManager batchTransactionManager(@Qualifier("primaryEntityManagerFactory")
  54. EntityManagerFactory
  55. primaryEntityManagerFactory) {
  56. return new JpaTransactionManager(primaryEntityManagerFactory);
  57. }
  58. @Bean
  59. public Job deleteCompletedTransaction(Step deleteStep,JobRepository jobRepository) {
  60. return new JobBuilder("deleteCompletedTransaction",jobRepository)
  61. .incrementer(new RunIdIncrementer())
  62. .start(deleteStep)
  63. .build();
  64. }
  65. @Bean("step1")
  66. public Step deleteTransaction(Tasklet deleteApmTransactionTasklet,
  67. PlatformTransactionManager transactionManager,JobRepository jobRepository) {
  68. return new StepBuilder("deleteTransaction", jobRepository)
  69. .allowStartIfComplete(Boolean.TRUE)
  70. .tasklet(deleteApmTransactionTasklet, transactionManager)
  71. .build();
  72. }
  73. }
  74. public class DeleteApmTransactionTasklet implements Tasklet {
  75. private static final Logger LOGGER = LoggerFactory.getLogger(DeleteApmTransactionTasklet.class);
  76. private static final int THREAD_DELAY = 1000;
  77. private static final String TRANSACTION_STATUS="DONE";
  78. // limit the number of records that are being processed at time in DB.
  79. private int batchSize;
  80. private final ApmTransactionRepository repository;
  81. public DeleteApmTransactionTasklet(ApmTransactionRepository repository,int batchSize) {
  82. this.repository= repository;
  83. this.batchSize=batchSize;
  84. }
  85. @Override
  86. public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
  87. try {
  88. LOGGER.info("Delete action is started.");
  89. long count = repository.getCountByStatus(TRANSACTION_STATUS);
  90. LOGGER.info("Number of transactions to be deleted {}", count);
  91. while (count > 0) {
  92. repository.deleteTrnInBatch(TRANSACTION_STATUS, batchSize);
  93. // Delay is in place in order to give DB a time to perform replication
  94. // Or any other background activity.
  95. Thread.sleep(1000);
  96. count = count - batchSize;
  97. }
  98. LOGGER.info("Completed transactions are deleted successfully");
  99. } catch (DataAccessException exception) {
  100. LOGGER.error("Transactions are not deleted successfully because of error {}", exception);
  101. return RepeatStatus.CONTINUABLE;
  102. }
  103. return RepeatStatus.FINISHED;
  104. }
  105. }
  106. @Repository
  107. public interface ApmTransactionRepository extends JpaRepository<ApmTransaction, String> {
  108. }
  109. @SpringBootApplication
  110. public class ApmBatchApplication {
  111. public static void main(String[] args) {
  112. System.exit(SpringApplication.exit(SpringApplication.run(DecoupledBatchApplication.class, args)));
  113. }
  114. }

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

6tdlim6h

6tdlim6h1#

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

相关问题