Spring Boot 1.4: Executing Method after Liquibase finished

后端 未结 2 1049

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

Is it possible to execute a Method AFTER liquibase finished?

Something like Bean Post Processor?

2条回答
  •  旧巷少年郎
    2021-02-20 06:56

    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");
        }
    
    }
    

提交回复
热议问题