Spring Boot 1.4:Liquibase完成后的执行方法 [英] Spring Boot 1.4: Executing Method after Liquibase finished

查看:475
本文介绍了Spring Boot 1.4:Liquibase完成后的执行方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Liquibase的基于Spring Boot 1.4.0的项目.

I have a Spring Boot 1.4.0 based Project that uses Liquibase.

是否可以在liquibase完成后执行方法?

Is it possible to execute a Method AFTER liquibase finished?

类似于Bean后处理器吗?

Something like Bean Post Processor?

在开发模式下启动应用程序时,我想做的是向数据库中添加一些数据.在开发模式下,该应用程序使用内存中的h2数据库,因此liquibase必须先创建表,然后才能写入数据.

What i want to do is adding some data to my database when the application is started in development mode. In developement mode the application uses an in-memory h2 database, so liquibase has to create the tables before i can write my data.

推荐答案

Spring Boot自动配置名为liquibaseSpringLiquibase bean. Liquibase完成后,将创建任何依赖于此bean的bean.例如,您可以使用@PostConstruct填充数据库:

Spring Boot auto-configures a SpringLiquibase bean named liquibase. Any bean that depends on this bean will be created after Liquibase has finished. For example, you could use @PostConstruct to populate the database:

@Bean
@DependsOn("liquibase")
public YourBean yourBean() {
    return new YourBean();
}

static class YourBean {

    @PostConstruct
    public void populateDatabase() {
        System.out.println("This will be called after Liquibase has finished");
    }

}

这篇关于Spring Boot 1.4:Liquibase完成后的执行方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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