Hack to force Flyway to initialize early

This commit is contained in:
Dave Syer 2014-05-17 09:17:01 +01:00
parent 341ca38d56
commit 2cc5bdfa09
3 changed files with 26 additions and 3 deletions

View File

@ -20,7 +20,9 @@ import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@ -31,6 +33,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
@ -52,7 +55,7 @@ public class FlywayAutoConfiguration {
@Configuration @Configuration
@ConditionalOnMissingBean(Flyway.class) @ConditionalOnMissingBean(Flyway.class)
@EnableConfigurationProperties(FlywayProperties.class) @EnableConfigurationProperties(FlywayProperties.class)
public static class LiquibaseConfiguration { public static class FlywayConfiguration {
@Autowired @Autowired
private FlywayProperties properties = new FlywayProperties(); private FlywayProperties properties = new FlywayProperties();
@ -93,6 +96,26 @@ public class FlywayAutoConfiguration {
return flyway; return flyway;
} }
@Bean
@DependsOn("flyway")
protected BeanPostProcessor forceFlywayToInitialize() {
return new BeanPostProcessor() {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
};
}
} }
} }

View File

@ -1,2 +1,2 @@
spring.jpa.generate-ddl: false spring.jpa.generate-ddl: false
spring.jpa.hibernate.ddl-auto: none spring.jpa.hibernate.ddl-auto: validate

View File

@ -1,5 +1,5 @@
CREATE TABLE PERSON ( CREATE TABLE PERSON (
id INTEGER GENERATED BY DEFAULT AS IDENTITY, id BIGINT GENERATED BY DEFAULT AS IDENTITY,
first_name varchar(255) not null, first_name varchar(255) not null,
last_name varchar(255) not null last_name varchar(255) not null
); );