diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java index 6fe7cde3df..eb7adeee46 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java @@ -24,7 +24,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SingleConnectionDataSource; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AbstractDatabaseInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AbstractDatabaseInitializer.java index 085e9693e3..5493b14894 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AbstractDatabaseInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AbstractDatabaseInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import javax.annotation.PostConstruct; import javax.sql.DataSource; import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.core.io.ResourceLoader; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; @@ -66,7 +67,18 @@ public abstract class AbstractDatabaseInitializer { DatabasePopulatorUtils.execute(populator, this.dataSource); } - protected abstract boolean isEnabled(); + private boolean isEnabled() { + if (getMode() == DatabaseInitializationMode.NEVER) { + return false; + } + if (getMode() == DatabaseInitializationMode.EMBEDDED + && !EmbeddedDatabaseConnection.isEmbedded(this.dataSource)) { + return false; + } + return true; + } + + protected abstract DatabaseInitializationMode getMode(); protected abstract String getSchemaLocation(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/DatabaseInitializationMode.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/DatabaseInitializationMode.java new file mode 100644 index 0000000000..51e1d0e63a --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/DatabaseInitializationMode.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +/** + * Supported {@link AbstractDatabaseInitializer database initializer} modes. + * + * @author Vedran Pavic + * @author Stephane Nicoll + * @since 2.0.0 + */ +public enum DatabaseInitializationMode { + + /** + * Always initialize the database. + */ + ALWAYS, + + /** + * Only initialize an embedded database. + */ + EMBEDDED, + + /** + * Do not initialize the database. + */ + NEVER + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDatabaseInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDatabaseInitializer.java index 20785e2222..6a634e7732 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDatabaseInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDatabaseInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.batch; import javax.sql.DataSource; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -40,8 +41,8 @@ public class BatchDatabaseInitializer extends AbstractDatabaseInitializer { } @Override - protected boolean isEnabled() { - return this.properties.getInitializer().isEnabled(); + protected DatabaseInitializationMode getMode() { + return this.properties.getInitializeSchema(); } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java index 65446ecc0d..6096dd8555 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.batch; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -42,7 +43,10 @@ public class BatchProperties { */ private String tablePrefix; - private final Initializer initializer = new Initializer(); + /** + * Database schema initialization mode. + */ + private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED; private final Job job = new Job(); @@ -62,38 +66,18 @@ public class BatchProperties { this.tablePrefix = tablePrefix; } - public Initializer getInitializer() { - return this.initializer; + public DatabaseInitializationMode getInitializeSchema() { + return this.initializeSchema; + } + + public void setInitializeSchema(DatabaseInitializationMode initializeSchema) { + this.initializeSchema = initializeSchema; } public Job getJob() { return this.job; } - public class Initializer { - - /** - * Create the required batch tables on startup if necessary. Enabled automatically - * if no custom table prefix is set or if a custom schema is configured. - */ - private Boolean enabled; - - public boolean isEnabled() { - if (this.enabled != null) { - return this.enabled; - } - boolean defaultTablePrefix = BatchProperties.this.getTablePrefix() == null; - boolean customSchema = !DEFAULT_SCHEMA_LOCATION - .equals(BatchProperties.this.getSchema()); - return (defaultTablePrefix || customSchema); - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - } - public static class Job { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 21640d89df..4ee9194d7c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -147,7 +147,6 @@ public class IntegrationAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnProperty(prefix = "spring.integration.jdbc.initializer", name = "enabled") public IntegrationDatabaseInitializer integrationDatabaseInitializer( DataSource dataSource, ResourceLoader resourceLoader, IntegrationProperties properties) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationDatabaseInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationDatabaseInitializer.java index 29d4d8f306..1ede99a04b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationDatabaseInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationDatabaseInitializer.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.integration; import javax.sql.DataSource; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -40,8 +41,8 @@ public class IntegrationDatabaseInitializer extends AbstractDatabaseInitializer } @Override - protected boolean isEnabled() { - return this.properties.getInitializer().isEnabled(); + protected DatabaseInitializationMode getMode() { + return this.properties.getInitializeSchema(); } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java index 3ebab5508d..f845fb8525 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.integration; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -44,7 +45,10 @@ public class IntegrationProperties { */ private String schema = DEFAULT_SCHEMA_LOCATION; - private final Initializer initializer = new Initializer(); + /** + * Database schema initialization mode. + */ + private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED; public String getSchema() { return this.schema; @@ -54,25 +58,12 @@ public class IntegrationProperties { this.schema = schema; } - public Initializer getInitializer() { - return this.initializer; + public DatabaseInitializationMode getInitializeSchema() { + return this.initializeSchema; } - public class Initializer { - - /** - * Create the required integration tables on startup. - */ - private boolean enabled = false; - - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - + public void setInitializeSchema(DatabaseInitializationMode initializeSchema) { + this.initializeSchema = initializeSchema; } } 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 45e68f59d6..ab84f1de95 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 @@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.Registrar; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Condition; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java index f702187a21..c3c0a0f1a3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.util.Assert; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java index d61c9c45aa..9496432a8f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java @@ -20,6 +20,7 @@ import javax.annotation.PreDestroy; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java index f0f857b503..f2f91ea556 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java @@ -21,8 +21,8 @@ import java.util.Map; import javax.sql.DataSource; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.orm.jpa.vendor.Database; import org.springframework.util.StringUtils; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDatabaseInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDatabaseInitializer.java index 63c3d52ab4..45d15e1af8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDatabaseInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDatabaseInitializer.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.quartz; import javax.sql.DataSource; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -40,8 +41,8 @@ public class QuartzDatabaseInitializer extends AbstractDatabaseInitializer { } @Override - protected boolean isEnabled() { - return this.properties.getJdbc().isInitializeSchema(); + protected DatabaseInitializationMode getMode() { + return this.properties.getJdbc().getInitializeSchema(); } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzProperties.java index 7f601444d3..c7a137b551 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzProperties.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.quartz; import java.util.HashMap; import java.util.Map; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -70,9 +71,9 @@ public class QuartzProperties { private String schema = DEFAULT_SCHEMA_LOCATION; /** - * Create the required Quartz Scheduler tables on startup. + * Database schema initialization mode. */ - private boolean initializeSchema; + private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED; public String getSchema() { return this.schema; @@ -82,11 +83,11 @@ public class QuartzProperties { this.schema = schema; } - public boolean isInitializeSchema() { + public DatabaseInitializationMode getInitializeSchema() { return this.initializeSchema; } - public void setInitializeSchema(boolean initializeSchema) { + public void setInitializeSchema(DatabaseInitializationMode initializeSchema) { this.initializeSchema = initializeSchema; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionDatabaseInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionDatabaseInitializer.java index 3823112e7d..4158974147 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionDatabaseInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionDatabaseInitializer.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.session; import javax.sql.DataSource; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -40,8 +41,8 @@ public class JdbcSessionDatabaseInitializer extends AbstractDatabaseInitializer } @Override - protected boolean isEnabled() { - return this.properties.getInitializer().isEnabled(); + protected DatabaseInitializationMode getMode() { + return this.properties.getInitializeSchema(); } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionProperties.java index 8b193bfb1a..31400dfba9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.session; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -42,7 +43,10 @@ public class JdbcSessionProperties { */ private String tableName = DEFAULT_TABLE_NAME; - private final Initializer initializer = new Initializer(); + /** + * Database schema initialization mode. + */ + private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED; public String getSchema() { return this.schema; @@ -60,32 +64,12 @@ public class JdbcSessionProperties { this.tableName = tableName; } - public Initializer getInitializer() { - return this.initializer; + public DatabaseInitializationMode getInitializeSchema() { + return this.initializeSchema; } - public class Initializer { - - /** - * Create the required session tables on startup if necessary. Enabled - * automatically if the default table name is set or a custom schema is - * configured. - */ - private Boolean enabled; - - public boolean isEnabled() { - if (this.enabled != null) { - return this.enabled; - } - boolean defaultTableName = DEFAULT_TABLE_NAME.equals(getTableName()); - boolean customSchema = !DEFAULT_SCHEMA_LOCATION.equals(getSchema()); - return (defaultTableName || customSchema); - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - + public void setInitializeSchema(DatabaseInitializationMode initializeSchema) { + this.initializeSchema = initializeSchema; } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index 49af2f91e8..51a089e7be 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -47,6 +47,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; @@ -86,8 +87,9 @@ public class BatchAutoConfigurationTests { EmbeddedDataSourceConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(JobLauncher.class); assertThat(context).hasSingleBean(JobExplorer.class); - assertThat(context.getBean(BatchProperties.class).getInitializer() - .isEnabled()).isTrue(); + assertThat( + context.getBean(BatchProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); }); @@ -169,11 +171,12 @@ public class BatchAutoConfigurationTests { .withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.datasource.generate-unique-name=true", - "spring.batch.initializer.enabled:false") + "spring.batch.initialize-schema:never") .run((context) -> { assertThat(context).hasSingleBean(JobLauncher.class); - assertThat(context.getBean(BatchProperties.class).getInitializer() - .isEnabled()).isFalse(); + assertThat( + context.getBean(BatchProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.NEVER); this.expected.expect(BadSqlGrammarException.class); new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION"); @@ -210,8 +213,9 @@ public class BatchAutoConfigurationTests { "spring.batch.tablePrefix:PREFIX_") .run((context) -> { assertThat(context).hasSingleBean(JobLauncher.class); - assertThat(context.getBean(BatchProperties.class).getInitializer() - .isEnabled()).isTrue(); + assertThat( + context.getBean(BatchProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION")) .isEmpty(); @@ -223,25 +227,6 @@ public class BatchAutoConfigurationTests { }); } - @Test - public void testCustomTablePrefixWithDefaultSchemaDisablesInitializer() - throws Exception { - this.contextRunner - .withUserConfiguration(TestConfiguration.class, - EmbeddedDataSourceConfiguration.class, - HibernateJpaAutoConfiguration.class) - .withPropertyValues("spring.datasource.generate-unique-name=true", - "spring.batch.tablePrefix:PREFIX_") - .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); - assertThat(context.getBean(BatchProperties.class).getInitializer() - .isEnabled()).isFalse(); - this.expected.expect(BadSqlGrammarException.class); - new JdbcTemplate(context.getBean(DataSource.class)) - .queryForList("select * from BATCH_JOB_EXECUTION"); - }); - } - @Test public void testCustomizeJpaTransactionManagerUsingProperties() throws Exception { this.contextRunner diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java index 5b617da956..d979bd4527 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java @@ -27,6 +27,7 @@ import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.test.City; @@ -66,8 +67,9 @@ public class BatchAutoConfigurationWithoutJpaTests { assertThat( context.getBean(PlatformTransactionManager.class).toString()) .contains("DataSourceTransactionManager"); - assertThat(context.getBean(BatchProperties.class).getInitializer() - .isEnabled()).isTrue(); + assertThat( + context.getBean(BatchProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); assertThat(context.getBean(JobExplorer.class) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index 6292ee97b0..178b836c9b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -26,6 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -152,9 +153,9 @@ public class IntegrationAutoConfigurationTests { DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class }, "spring.datasource.generate-unique-name=true", - "spring.integration.jdbc.initializer.enabled=true"); + "spring.integration.jdbc.initialize-schema=always"); assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() - .getInitializer().isEnabled()).isTrue(); + .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.ALWAYS); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); assertThat(jdbcOperations.queryForList("select * from INT_MESSAGE")).isEmpty(); assertThat(jdbcOperations.queryForList("select * from INT_GROUP_TO_MESSAGE")) @@ -172,25 +173,24 @@ public class IntegrationAutoConfigurationTests { DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class }, "spring.datasource.generate-unique-name=true", - "spring.integration.jdbc.initializer.enabled=false"); + "spring.integration.jdbc.initialize-schema=never"); assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() - .getInitializer().isEnabled()).isFalse(); + .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.NEVER); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); this.thrown.expect(BadSqlGrammarException.class); jdbcOperations.queryForList("select * from INT_MESSAGE"); } @Test - public void integrationJdbcDatabaseInitializerDisabledByDefault() { + public void integrationJdbcDatabaseInitializerEnabledByDefaultWithEmbeddedDb() { load(new Class[] { EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class }, "spring.datasource.generate-unique-name=true"); assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() - .getInitializer().isEnabled()).isFalse(); + .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.EMBEDDED); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); - this.thrown.expect(BadSqlGrammarException.class); - jdbcOperations.queryForList("select * from INT_MESSAGE"); + jdbcOperations.queryForList("select * from INT_MESSAGE").isEmpty(); } private static void assertDomains(MBeanServer mBeanServer, boolean expected, diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 356ce186fa..1c45887217 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.jdbc; +import java.net.URL; +import java.net.URLClassLoader; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverPropertyInfo; @@ -39,6 +41,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.test.context.HidePackagesClassLoader; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -81,16 +84,11 @@ public class DataSourceAutoConfigurationTests { @Test public void testBadUrl() throws Exception { - try { - EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE; - this.contextRunner - .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") - .run((context) -> assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class)); - } - finally { - EmbeddedDatabaseConnection.override = null; - } + this.contextRunner + .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") + .withClassLoader(new DisableEmbeddedDatabaseClassLoader()) + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class)); } @Test @@ -311,4 +309,24 @@ public class DataSourceAutoConfigurationTests { } + private static class DisableEmbeddedDatabaseClassLoader extends URLClassLoader { + + DisableEmbeddedDatabaseClassLoader() { + super(new URL[0], DisableEmbeddedDatabaseClassLoader.class.getClassLoader()); + } + + @Override + protected Class loadClass(String name, boolean resolve) + throws ClassNotFoundException { + for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) { + if (name.equals(candidate.getDriverClassName())) { + throw new ClassNotFoundException(); + } + } + return super.loadClass(name, resolve); + } + + } + + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java index 0468eafaa3..380f685e78 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java @@ -68,7 +68,6 @@ public class DataSourceInitializerTests { @Before public void init() { - EmbeddedDatabaseConnection.override = null; TestPropertyValues.of("spring.datasource.initialize:false", "spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt()) .applyTo(this.context); @@ -76,7 +75,6 @@ public class DataSourceInitializerTests { @After public void restore() { - EmbeddedDatabaseConnection.override = null; if (this.context != null) { this.context.close(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java index b5c7eaaafb..d4b4ddf192 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java @@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.jdbc; import org.junit.Test; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; + import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDataSourceConfigurationTests.java index 087507e7ad..88415a8606 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDataSourceConfigurationTests.java @@ -45,7 +45,6 @@ public class HikariDataSourceConfigurationTests { if (this.context != null) { this.context.close(); } - EmbeddedDatabaseConnection.override = null; } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index 46dd5cf92f..a3862737b4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -23,7 +23,6 @@ import javax.sql.DataSource; import org.apache.tomcat.jdbc.pool.DataSourceProxy; import org.apache.tomcat.jdbc.pool.PoolProperties; import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -56,11 +55,6 @@ public class TomcatDataSourceConfigurationTests { TestPropertyValues.of(PREFIX + "initialize:false").applyTo(this.context); } - @After - public void restore() { - EmbeddedDatabaseConnection.override = null; - } - @Test public void testDataSourceExists() throws Exception { this.context.register(TomcatDataSourceConfiguration.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java index 0f1240d753..351881cb17 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java @@ -107,8 +107,7 @@ public class QuartzAutoConfigurationTests { load(new Class[] { QuartzJobsConfiguration.class, EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class }, - "spring.quartz.job-store-type=jdbc", - "spring.quartz.jdbc.initialize-schema=true"); + "spring.quartz.job-store-type=jdbc"); testWithDataSource(); } @@ -116,8 +115,7 @@ public class QuartzAutoConfigurationTests { public void withDataSourceNoTransactionManager() throws Exception { load(new Class[] { QuartzJobsConfiguration.class, EmbeddedDataSourceConfiguration.class }, - "spring.quartz.job-store-type=jdbc", - "spring.quartz.jdbc.initialize-schema=true"); + "spring.quartz.job-store-type=jdbc"); testWithDataSource(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java index 13232b77af..ab841872c2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java @@ -23,6 +23,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.DirectFieldAccessor; +import org.springframework.boot.autoconfigure.DatabaseInitializationMode; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; @@ -54,8 +55,9 @@ public class SessionAutoConfigurationJdbcTests JdbcOperationsSessionRepository.class); assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) .isEqualTo("SPRING_SESSION"); - assertThat(this.context.getBean(JdbcSessionProperties.class).getInitializer() - .isEnabled()).isTrue(); + assertThat( + this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(this.context.getBean(JdbcOperations.class) .queryForList("select * from SPRING_SESSION")).isEmpty(); } @@ -65,13 +67,14 @@ public class SessionAutoConfigurationJdbcTests load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc", - "spring.session.jdbc.initializer.enabled=false"); + "spring.session.jdbc.initialize-schema=never"); JdbcOperationsSessionRepository repository = validateSessionRepository( JdbcOperationsSessionRepository.class); assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) .isEqualTo("SPRING_SESSION"); - assertThat(this.context.getBean(JdbcSessionProperties.class).getInitializer() - .isEnabled()).isFalse(); + assertThat( + this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.NEVER); this.thrown.expect(BadSqlGrammarException.class); assertThat(this.context.getBean(JdbcOperations.class) .queryForList("select * from SPRING_SESSION")).isEmpty(); @@ -88,27 +91,11 @@ public class SessionAutoConfigurationJdbcTests JdbcOperationsSessionRepository.class); assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) .isEqualTo("FOO_BAR"); - assertThat(this.context.getBean(JdbcSessionProperties.class).getInitializer() - .isEnabled()).isTrue(); + assertThat( + this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(this.context.getBean(JdbcOperations.class) .queryForList("select * from FOO_BAR")).isEmpty(); } - @Test - public void customTableNameWithDefaultSchemaDisablesInitializer() { - load(Arrays.asList(EmbeddedDataSourceConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class), - "spring.session.store-type=jdbc", - "spring.session.jdbc.table-name=FOO_BAR"); - JdbcOperationsSessionRepository repository = validateSessionRepository( - JdbcOperationsSessionRepository.class); - assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) - .isEqualTo("FOO_BAR"); - assertThat(this.context.getBean(JdbcSessionProperties.class).getInitializer() - .isEnabled()).isFalse(); - this.thrown.expect(BadSqlGrammarException.class); - assertThat(this.context.getBean(JdbcOperations.class) - .queryForList("select * from SPRING_SESSION")).isEmpty(); - } - } diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 5981e6b7c5..c1f5a45e8e 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -132,7 +132,7 @@ content into your application; rather pick only the properties that you need. # QUARTZ SCHEDULER ({sc-spring-boot-autoconfigure}/quartz/QuartzProperties.{sc-ext}[QuartzProperties]) spring.quartz.job-store-type=memory # Quartz job store type. spring.quartz.properties.*= # Additional Quartz Scheduler properties. - spring.quartz.jdbc.initialize-schema=false # Create the required Quartz Scheduler tables on startup. + spring.quartz.jdbc.initialize-schema=embedded # Database schema initialization mode. spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema. # Reactor @@ -416,7 +416,7 @@ content into your application; rather pick only the properties that you need. # SPRING SESSION ({sc-spring-boot-autoconfigure}/session/SessionProperties.{sc-ext}[SessionProperties]) spring.session.hazelcast.flush-mode=on-save # Sessions flush mode. spring.session.hazelcast.map-name=spring:session:sessions # Name of the map used to store sessions. - spring.session.jdbc.initializer.enabled= # Create the required session tables on startup if necessary. Enabled automatically if the default table name is set or a custom schema is configured. + spring.session.jdbc.initialize-schema=embedded # Database schema initialization mode. spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.session.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions. spring.session.redis.flush-mode=on-save # Sessions flush mode. @@ -942,14 +942,14 @@ content into your application; rather pick only the properties that you need. spring.artemis.user= # Login user of the broker. # SPRING BATCH ({sc-spring-boot-autoconfigure}/batch/BatchProperties.{sc-ext}[BatchProperties]) - spring.batch.initializer.enabled= # Create the required batch tables on startup if necessary. Enabled automatically if no custom table prefix is set or if a custom schema is configured. + spring.batch.initialize-schema=embedded # Database schema initialization mode. spring.batch.job.enabled=true # Execute all Spring Batch jobs in the context on startup. spring.batch.job.names= # Comma-separated list of job names to execute on startup (For instance `job1,job2`). By default, all Jobs found in the context are executed. spring.batch.schema=classpath:org/springframework/batch/core/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.batch.table-prefix= # Table prefix for all the batch meta-data tables. # SPRING INTEGRATION ({sc-spring-boot-autoconfigure}/integration/IntegrationProperties.{sc-ext}[IntegrationProperties]) - spring.integration.jdbc.initializer.enabled=false # Create the required integration tables on startup. + spring.integration.jdbc.initialize-schema=embedded # Database schema initialization mode. spring.integration.jdbc.schema=classpath:org/springframework/integration/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema. # JMS ({sc-spring-boot-autoconfigure}/jms/JmsProperties.{sc-ext}[JmsProperties]) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 764aa98648..4338c6b393 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1935,12 +1935,17 @@ data. [[howto-initialize-a-spring-batch-database]] === Initialize a Spring Batch database If you are using Spring Batch then it comes pre-packaged with SQL initialization scripts -for most popular database platforms. Spring Boot will detect your database type, and -execute those scripts by default, and in this case will switch the fail fast setting to -false (errors are logged but do not prevent the application from starting). This is -because the scripts are known to be reliable and generally do not contain bugs, so errors -are ignorable, and ignoring them makes the scripts idempotent. You can switch off the -initialization explicitly using `spring.batch.initializer.enabled=false`. +for most popular database platforms. Spring Boot can detect your database type and +execute those scripts on startup. If you are using an embedded database this happens +by default. You can also enable it for any database type: + +[indent=0,subs="verbatim,quotes,attributes"] +---- + spring.batch.initialize-schema=always +---- + +You can also switch off the initialization explicitly using +`spring.batch.initialize-schema=never`. diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 5db4040d1a..1d64a16679 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -5568,7 +5568,7 @@ on startup: [source,properties,indent=0] ---- - spring.integration.jdbc.initializer.enabled=true + spring.integration.jdbc.initialize-schema=always ---- See the diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java index 92eaf5fcdf..41c677dcb0 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java @@ -26,7 +26,7 @@ import java.lang.annotation.Target; import javax.sql.DataSource; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping; diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java index 8068c39990..ef6fea1dc0 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java @@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java index 1fd4d7789f..6aa8fcd1c0 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java index 218f46e4bf..3d9b03229e 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java index 4dcad35dce..6d0c09fc6f 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java index c1d6c6ab2f..bd459250c1 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestWithAutoConfigureTestDatabaseIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestWithAutoConfigureTestDatabaseIntegrationTests.java index 4babbca026..491cca9748 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestWithAutoConfigureTestDatabaseIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestWithAutoConfigureTestDatabaseIntegrationTests.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java b/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java similarity index 95% rename from spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java rename to spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java index b3cb57e24f..eccfafac17 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java +++ b/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.jdbc; +package org.springframework.boot.jdbc; import java.sql.Connection; import java.sql.SQLException; @@ -109,11 +109,6 @@ public enum EmbeddedDatabaseConnection { return String.format(this.url, databaseName); } - /** - * Override for testing. - */ - static EmbeddedDatabaseConnection override; - /** * Convenience method to determine if a given driver class name represents an embedded * database type. @@ -149,9 +144,6 @@ public enum EmbeddedDatabaseConnection { * @return an {@link EmbeddedDatabaseConnection} or {@link #NONE}. */ public static EmbeddedDatabaseConnection get(ClassLoader classLoader) { - if (override != null) { - return override; - } for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) { if (candidate != NONE && ClassUtils.isPresent(candidate.getDriverClassName(), classLoader)) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnectionTests.java b/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java similarity index 93% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnectionTests.java rename to spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java index 7a2286ccb8..cc0cb9e1b0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnectionTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.jdbc; +package org.springframework.boot.jdbc; import org.junit.Rule; import org.junit.Test;