You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Spring的application.yaml中正确配置Liquibase的preserveSchemaCase参数?

Spring Boot中Liquibase preserveSchemaCase配置不生效的解决方法

你遇到的核心问题是混淆了Liquibase的两种配置参数类型:

  • spring.liquibase.parameters是用于传递changelog脚本中的占位符参数(比如在changelog里写${table-prefix}),并非Liquibase的全局核心配置项,所以不管怎么命名变体都不会对preserveSchemaCase这类全局参数生效。
  • Liquibase的全局配置参数需要通过spring.liquibase.properties来配置,这个属性对应Spring Boot自动配置中LiquibaseProperties的properties字段,会直接传递给Liquibase实例的底层配置。

正确的application.yaml配置方式

spring:
  liquibase:
    properties:
      preserveSchemaCase: true

原理说明

Spring Boot的Liquibase自动配置类会将spring.liquibase.properties中的键值对,转换为Liquibase的配置属性,注入到Database或Liquibase实例中,这和你通过环境变量LIQUIBASE_PRESERVE_SCHEMA_CASE或System.setProperty("liquibase.preserveSchemaCase")的生效逻辑一致,都是设置Liquibase的全局系统级参数。

备选方案(自定义Bean)

如果你的Spring Boot版本不支持spring.liquibase.properties(极少情况),可以自定义Liquibase Bean手动设置参数:

@Bean
public Liquibase liquibase(DataSource dataSource, LiquibaseProperties properties) throws SQLException {
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));
    database.setPreserveSchemaCase(true);
    
    // 其他默认配置逻辑
    Liquibase liquibase = new Liquibase(
        properties.getChangeLog(),
        new ClassLoaderResourceAccessor(),
        database
    );
    liquibase.setContexts(properties.getContexts());
    liquibase.setLabels(properties.getLabels());
    liquibase.setChangeLogParameters(properties.getParameters());
    return liquibase;
}

内容的提问来源于stack exchange,提问作者oligofren

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:05:07