From 7d213950ad393dab636a7844e960b78498690b0b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 6 Aug 2014 14:48:26 +0100 Subject: [PATCH] Never run data.sql scripts if spring.datasource.initialize is false Previously, the data scripts were always run in response to the publication of a DataSourceInitializedEvent, irrespective of spring.datasource.initialize. While the event won't be published by DataSourceInitializer if spring.datasource.initialize is false, it will be published if spring.jpa.hibernate.hbm2ddl.auto has been set. This commit updates DataSourceInitializer's handling of DataSourceInitializedEvent to only run the data scripts if spring.datasource.initialize is true. Fixes #1336 --- .../jdbc/DataSourceInitializer.java | 4 ++ .../jdbc/DataSourceInitializerTests.java | 72 ++++++++++++++----- .../src/test/resources/data.sql | 1 + .../boot/autoconfigure/jdbc/data.sql | 1 + 4 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 spring-boot-autoconfigure/src/test/resources/data.sql create mode 100644 spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/jdbc/data.sql 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 22c29b20ec..bfb76b437d 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 @@ -88,6 +88,10 @@ class DataSourceInitializer implements ApplicationListener