From f8e847a6fcde2ba53de81724361dbeaa0a5c126f Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 18 Jun 2014 15:19:53 +0100 Subject: [PATCH] Change ordering of DataSourceInitializer a bit It needs to run as soon as the DataSource is available really otherwise anything else that depends on the DataSource (like Security JDBC initializers) might fail when it tries to use it. One change from 1.1.1 is that if you have a schema.sql you had better make sure your data.sql talks to the same tables. In 1.1.1 you could sometimes get away with letting Hibernate initialize the tables for your data.sql and *also* have a schema.sql. This was fragile and doomed to fail eventually if the DataSourceInitializer somehow got initialized earlier (e.g. through a @DependsOn), so in the spririt of honesty being the best policy we explicitly disallow it now. Fixes gh-1115 --- .../jdbc/DataSourceAutoConfiguration.java | 2 + .../jdbc/DataSourceInitializer.java | 4 +- .../DataSourceInitializerPostProcessor.java | 83 +++++++++++++++++++ .../HibernateJpaAutoConfigurationTests.java | 5 +- .../ui/secure/SampleWebSecureApplication.java | 2 - 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerPostProcessor.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java index dd157c2149..0cf6eb1b48 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; +import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.Registrar; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -52,6 +53,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @Configuration @ConditionalOnClass(EmbeddedDatabaseType.class) @EnableConfigurationProperties(DataSourceProperties.class) +@Import(Registrar.class) public class DataSourceAutoConfiguration { public static final String CONFIGURATION_PREFIX = "spring.datasource"; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index 6a233c6304..acd1d9173b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -82,8 +82,8 @@ class DataSourceInitializer implements ApplicationListener