diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 036df46e65..03eb7957f6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -20,7 +20,9 @@ import javax.annotation.PostConstruct; import javax.sql.DataSource; import org.flywaydb.core.Flyway; +import org.springframework.beans.BeansException; 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.EnableAutoConfiguration; 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.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -52,7 +55,7 @@ public class FlywayAutoConfiguration { @Configuration @ConditionalOnMissingBean(Flyway.class) @EnableConfigurationProperties(FlywayProperties.class) - public static class LiquibaseConfiguration { + public static class FlywayConfiguration { @Autowired private FlywayProperties properties = new FlywayProperties(); @@ -93,6 +96,26 @@ public class FlywayAutoConfiguration { 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; + } + + }; + } } } diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties index ab647f3d61..56a7217665 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.jpa.generate-ddl: false -spring.jpa.hibernate.ddl-auto: none \ No newline at end of file +spring.jpa.hibernate.ddl-auto: validate \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migrations/V1__init.sql b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migrations/V1__init.sql index 8038f342ea..e6ac47ce65 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migrations/V1__init.sql +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migrations/V1__init.sql @@ -1,5 +1,5 @@ CREATE TABLE PERSON ( - id INTEGER GENERATED BY DEFAULT AS IDENTITY, + id BIGINT GENERATED BY DEFAULT AS IDENTITY, first_name varchar(255) not null, last_name varchar(255) not null );