运行 Tomcat 下的 liquibase?

Run liquibase under Tomcat?

如何按计划根据 Tomcat 下的基线启动 liquibase 模式数据库检查?比如如何在Tomcat下部署liquibase?

如何利用 ServletContextListener 并在其中创建新对象 Liquibase.

类似

import java.sql.Connection;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.CompositeResourceAccessor;
import liquibase.resource.FileSystemResourceAccessor;
import lombok.SneakyThrows;

@WebListener
public class LiquibaseListener implements ServletContextListener {

  @SneakyThrows
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    final Connection connection = null;
    final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
    final Liquibase liquibase = new Liquibase("changelogpath", new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new FileSystemResourceAccessor()), database);
    liquibase.update("");
    
  }
}

或者看看 SpringLiquibase spring 框架是如何完成的,您可以从那里获得灵感。