如何使用 spring boot 和 Liquibase 变更集 yaml 文件访问系统属性 [英] how can I access system properties using spring boot and Liquibase changeset yaml file

查看:48
本文介绍了如何使用 spring boot 和 Liquibase 变更集 yaml 文件访问系统属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Liquibase 管理数据库架构更改的 Spring Boot Java 应用程序使用指定其运行环境的参数(例如 dev、int)启动.

A Spring Boot Java application using Liquibase to manage the database schema changes is started with a parameter (e.g. dev, int) specifying the environment it runs in.

有相应的属性文件(例如 dev.properties、int.properties)为相应的环境定义属性.

There are corresponding properties files (e.g. dev.properties, int.properties) which define properties for the corresponding environment.

所以在 dev.properties 中有例如

So in dev.properties there is e.g.

url.info=http://dev.app.info

在 tst.properties 中有

and in tst.properties there is

url.info=http://tst.app.info

应用程序从与传入参数对应的文件中读取属性.

The application reads in the properties from the file corresponding to the passed in parameter.

当应用程序在每个环境中部署和启动时,这种机制工作正常.使用相应属性的实例很多.

This mechanism works fine when the application is deployed and started in each environment. There are many instances when the corresponding property is used.

但是,它不适用于包含以下插入语句的 Liquibase yaml 变更集

However, it doesn't work with a Liquibase yaml changeset containing the following insert statement

- insert:
        tableName: result
        columns:
          - column:
              name: id
              value: a88b6708-5c9f-40c4-a3ca-41e7a6b57fc8
          - column:
              name: infoUrl
              value: ${url.info}

我在 yaml 文件中尝试了双引号和单引号,即 "${url.info}" 和 '${url.info}' 但数据库总是以字符串 ${url.info} 结束

I have tried double and single quotes in the yaml file, i.e. "${url.info}" and '${url.info}' but the database always ends up with the String ${url.info}

我必须对 yaml 文件中的属性使用另一种表示法吗?或在 liquibase yaml 文件中不能像在 xml 文件中那样引用属性吗?

Is there another notation I have to use for properties in yaml files? or Can properties not be referenced in liquibase yaml files the way they can with xml files?

推荐答案

当你使用 Spring Boot 时,你可以使用它的 application.properties 文件来定义 更改日志参数.

As you are using Spring Boot, you can use its application.properties file to define change log parameters.

名称以 liquibase.parameters. 开头的任何属性都可以在变更日志中引用.例如,属性 liquibase.parameters.url.info 可以在更改日志(YAML 或 XML)中引用为 ${url.info}.

Any property with a name that begins with liquibase.parameters. can be referenced in a changelog. For example, the property liquibase.parameters.url.info can be referenced as ${url.info} in your changelog (YAML or XML).

要为开发、QA、生产等使用不同的配置文件,您可以使用配置文件和特定于配置文件的配置文件.例如,application-dev.properties 文件只会在 dev 配置文件处于活动状态时加载.

To use different configuration files for dev, QA, production etc you can use profiles and profile-specific configuration files. For example, the application-dev.properties file will only be loaded when the dev profile is active.

这篇关于如何使用 spring boot 和 Liquibase 变更集 yaml 文件访问系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆