【问题标题】:Flyway servlet initializationFlyway servlet 初始化
【发布时间】:2012-12-07 16:10:41
【问题描述】:

Liquibase 有一个 servlet 选项来初始化数据库。 http://liquibase.org/manual/servlet_listener

Flyway 有这样的例子吗?或者,更好的工作 servlet?

【问题讨论】:

    标签: flyway


    【解决方案1】:

    您真正想要的是在启动时运行flyway.migrate()。这可以通过多种方式来实现,Servlet 监听器就是其中之一。

    没有开箱即用的 servlet 侦听器,但您可以自己动手制作。

    它应该看起来像这样:

    @WebListener
    public class FlywayListener implements ServletContextListener {
    
        public void contextInitialized(ServletContextEvent sce) {
            Flyway flyway = new Flyway();
            flyway.setDataSource(...);
            flyway.migrate();
        }
    
        public void contextDestroyed(ServletContextEvent sce) {
        }
    }
    

    实现ServletContextListener 接口的类被称为before 第一个servlet(或过滤器)调用和after 最后一个。 @WebListener 注释是通知 Servlet 容器您的预期侦听器的一种方式。有关详细信息,请参阅 this Oracle Tutorialsearch Stack Overflow

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-15
    • 2016-06-14
    • 2020-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 2014-04-23
    相关资源
    最近更新 更多