相关疑难解决方法(0)

从属性文件加载数据,以供Liquibase在Maven构建中使用

我可以通过maven build(liquibase:update目标)运行Liquibase changelog 而不会出现任何问题.现在,我希望Liquibase使用数据库凭据和从属性文件(db.properties)加载的URL,具体取决于所选的Maven配置文件:

|-- pom.xml
`-- src
    `-- main
        `-- resources
            |-- local
            |   `-- db.properties
            |-- dev
            |   `-- db.properties
            |-- prod
            |   `-- db.properties
            `-- db-changelog-master.xml
            `-- db-changelog-1.0.xml
Run Code Online (Sandbox Code Playgroud)

3个属性文件中的每一个都如下所示:

database.driver = oracle.jdbc.driver.OracleDriver
database.url = jdbc:oracle:thin:@<host_name>:<port_number>/instance
database.username = user
database.password = password123
Run Code Online (Sandbox Code Playgroud)

现在,而不是在POM文件本身中定义这些属性(正如在这个问题的接受答案中所解释的,liquibase使用带有两个数据库的maven不起作用),我希望它们从外部属性文件加载.我试过不同的方法无济于事:

1.我resource在POM文件中使用了Maven的元素:

<build>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>org.liquibase</groupId>
               <artifactId>liquibase-maven-plugin</artifactId>
               <version>3.1.0</version>
               <configuration>
                  <changeLogFile>db.changelog-master.xml</changeLogFile>
                  <verbose>true</verbose>
               </configuration>
            </plugin>
         </plugins>
      </pluginManagement>
   </build>


<profiles>
    <profile>
        <id>local</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources/local</directory>
                </resource> …
Run Code Online (Sandbox Code Playgroud)

java liquibase maven

9
推荐指数
1
解决办法
2万
查看次数

使用带有liquibase changeset context属性的spring boot配置文件来管理changset范围

我试图用spring boot和liquibase做一个概念验证应用程序.我基本上想要创建一个可以通过使用名为context的changeset属性管理liquibase更改集的spring boot应用程序,这样没有上下文的changeset可以应用于任何spring引导配置文件,而具有特定上下文的changeset(例如context ="dev")仅当该类型的弹簧引导配置文件处于活动状态时才会应用(例如spring.profiles.active = dev).

在我的应用程序中,我有以下弹簧配置文件 - > dev,prod(每个在应用程序yaml文件中正确指定,并在配置文件下指定了相关配置文件数据库凭据).我需要做些什么来完成这项工作.下面是我的application.yaml

spring:
  application:
    name: liquibase-spring-jpa-postgres-example
liquibase:
  change-log: db.changelog/db.changelog-master.xml

spring:
  profiles: dev
  datasource:
    url: jdbc:postgresql://localhost:5432/dev
    username: postgres
    password: password
    driver-class-name: org.postgresql.Driver

spring:
  profiles: ci
  datasource:
      url: jdbc:postgresql://localhost:5432/ci
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver

spring:
  profiles: qa
  datasource:
      url: jdbc:postgresql://localhost:5432/qa
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver

spring:
  profiles: production
  datasource:
      url: jdbc:postgresql://localhost:5432/prod
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver
Run Code Online (Sandbox Code Playgroud)

以下是当前的databaseChangeLog文件(如果我的弹簧配置文件是prod,则第二个更改集不应该运行).

<changeSet id="20161016_my_first_change" author="fike" context="dev, qa, ci, production">
    <sql>
        CREATE TABLE customer
        (
        id BIGSERIAL …
Run Code Online (Sandbox Code Playgroud)

postgresql liquibase spring-boot liquibase-hibernate

2
推荐指数
2
解决办法
7306
查看次数