首页 > 解决方案 > 为什么 Spring Batch 在我的 Ubuntu 20.04 机器上的 MySql 上创建小写表?

问题描述

我正在开发一个 Spring Batch 项目(在 Spring Boot 上运行),我遇到了一个棘手的问题。

基本上直到现在我都使用 H2 数据库。为了投入生产(在 Ubuntu 20.04 机器上),我试图用 MySql 替换它。

这是我的application.properties初始配置(使用 H2 数据库):

#Database Configuration
spring.datasource.url=jdbc:h2:mem:springbatch;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=

因此,我使用 MySql 而不是 H2 将这些配置替换为这些新配置:

spring.datasource.platform=mysql
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/spring
spring.datasource.username=andrea
spring.datasource.password=Aprile_12_Test
spring.datasource.initialization-mode=always

如您所见,初始化模式设置为始终运行我的 Spring Batch 应用程序,表将被创建到我的spring MySql 数据库中。表已创建但它们是小写的(进入使用的schema-mysql.sql文件都是大写的:

mysql> show tables;
+------------------------------+
| Tables_in_spring             |
+------------------------------+
| BATCH_JOB_EXECUTION          |
| BATCH_JOB_INSTANCE           |
| DATABASECHANGELOG            |
| DATABASECHANGELOGLOCK        |
| batch_job_execution          |
| batch_job_execution_context  |
| batch_job_execution_params   |
| batch_job_instance           |
| batch_step_execution         |
| batch_step_execution_context |
+------------------------------+

这似乎是一些错误的原因,因为它不会使用带有大写引用的表创建其他表。

为什么我会面临这个问题?我能做些什么来解决这个问题?是否存在指定使用.sql 文件中定义的大写名称的方法?

标签: mysqlspringspring-bootspring-batch

解决方案


由我自己解决,允许 Spring Boot\Batch 第一次创建数据库表。进入application.properties ::

spring.datasource.initialization-mode=always

从 pom.xml 中删除 Liquidebase 库:

<!-- 
<dependency>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-core</artifactId>
    <scope>runtime</scope>
</dependency>
-->

最后在application.properties中禁用数据库表创建:

spring.datasource.initialization-mode=never

最后运行批处理。问题似乎是液基。


推荐阅读