如何在没有 Spring 的情况下 运行 Liquibase 迁移,仅借助 Java?

How to run Liquibase migration without Spring, only by help of Java?

我尝试在没有任何相邻框架的情况下使用 Liquibase,仅在 Java 的帮助下,我遇到了如何 运行 Liquibase 的问题。我从官方文档中找到了一个例子:

java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());

但我更喜欢使用设置位于资源文件夹中的 liquibase.property 文件。当我使用 Spring 和 Hibernate 时它工作正常,我只是在 application.properties 文件中写了一个属性,仅此而已,但是在这种情况下如何操作?

这个呢?

Properties properties = new Properties();
// load properties from classpath
    
java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
try (Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database)){
  properties.forEach((key, value) -> liquibase.setChangeLogParameter(Objects.toString(key), value));
  liquibase.update(new Contexts(), new LabelExpression());
}