Commit 394371eb authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Harmonize database initializers"

Closes gh-9752
parent 14b7be83
...@@ -24,7 +24,7 @@ import org.junit.After; ...@@ -24,7 +24,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource; import org.springframework.jdbc.datasource.SingleConnectionDataSource;
......
...@@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure; ...@@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
...@@ -53,8 +53,7 @@ public abstract class AbstractDatabaseInitializer { ...@@ -53,8 +53,7 @@ public abstract class AbstractDatabaseInitializer {
@PostConstruct @PostConstruct
protected void initialize() { protected void initialize() {
if ((getMode() == DatabaseInitializerMode.EMBEDDED && !isEmbeddedDataSource()) if (!isEnabled()) {
|| getMode() == DatabaseInitializerMode.NEVER) {
return; return;
} }
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
...@@ -68,7 +67,18 @@ public abstract class AbstractDatabaseInitializer { ...@@ -68,7 +67,18 @@ public abstract class AbstractDatabaseInitializer {
DatabasePopulatorUtils.execute(populator, this.dataSource); DatabasePopulatorUtils.execute(populator, this.dataSource);
} }
protected abstract DatabaseInitializerMode getMode(); 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(); protected abstract String getSchemaLocation();
...@@ -88,8 +98,4 @@ public abstract class AbstractDatabaseInitializer { ...@@ -88,8 +98,4 @@ public abstract class AbstractDatabaseInitializer {
} }
} }
private boolean isEmbeddedDataSource() {
return EmbeddedDatabaseConnection.isEmbedded(this.dataSource);
}
} }
...@@ -20,22 +20,23 @@ package org.springframework.boot.autoconfigure; ...@@ -20,22 +20,23 @@ package org.springframework.boot.autoconfigure;
* Supported {@link AbstractDatabaseInitializer database initializer} modes. * Supported {@link AbstractDatabaseInitializer database initializer} modes.
* *
* @author Vedran Pavic * @author Vedran Pavic
* @author Stephane Nicoll
* @since 2.0.0 * @since 2.0.0
*/ */
public enum DatabaseInitializerMode { public enum DatabaseInitializationMode {
/** /**
* Always enabled. * Always initialize the database.
*/ */
ALWAYS, ALWAYS,
/** /**
* Enabled when using an embedded database. * Only initialize an embedded database.
*/ */
EMBEDDED, EMBEDDED,
/** /**
* Never enabled. * Do not initialize the database.
*/ */
NEVER NEVER
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.batch; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.batch;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -41,7 +41,7 @@ public class BatchDatabaseInitializer extends AbstractDatabaseInitializer { ...@@ -41,7 +41,7 @@ public class BatchDatabaseInitializer extends AbstractDatabaseInitializer {
} }
@Override @Override
protected DatabaseInitializerMode getMode() { protected DatabaseInitializationMode getMode() {
return this.properties.getInitializeSchema(); return this.properties.getInitializeSchema();
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.batch; package org.springframework.boot.autoconfigure.batch;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -44,9 +44,9 @@ public class BatchProperties { ...@@ -44,9 +44,9 @@ public class BatchProperties {
private String tablePrefix; private String tablePrefix;
/** /**
* Spring Batch database schema initialization mode. * Database schema initialization mode.
*/ */
private DatabaseInitializerMode initializeSchema = DatabaseInitializerMode.EMBEDDED; private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
private final Job job = new Job(); private final Job job = new Job();
...@@ -66,11 +66,11 @@ public class BatchProperties { ...@@ -66,11 +66,11 @@ public class BatchProperties {
this.tablePrefix = tablePrefix; this.tablePrefix = tablePrefix;
} }
public DatabaseInitializerMode getInitializeSchema() { public DatabaseInitializationMode getInitializeSchema() {
return this.initializeSchema; return this.initializeSchema;
} }
public void setInitializeSchema(DatabaseInitializerMode initializeSchema) { public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
this.initializeSchema = initializeSchema; this.initializeSchema = initializeSchema;
} }
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.integration; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.integration;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -41,7 +41,7 @@ public class IntegrationDatabaseInitializer extends AbstractDatabaseInitializer ...@@ -41,7 +41,7 @@ public class IntegrationDatabaseInitializer extends AbstractDatabaseInitializer
} }
@Override @Override
protected DatabaseInitializerMode getMode() { protected DatabaseInitializationMode getMode() {
return this.properties.getInitializeSchema(); return this.properties.getInitializeSchema();
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.integration; package org.springframework.boot.autoconfigure.integration;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -46,9 +46,9 @@ public class IntegrationProperties { ...@@ -46,9 +46,9 @@ public class IntegrationProperties {
private String schema = DEFAULT_SCHEMA_LOCATION; private String schema = DEFAULT_SCHEMA_LOCATION;
/** /**
* Spring Integration database schema initialization mode. * Database schema initialization mode.
*/ */
private DatabaseInitializerMode initializeSchema = DatabaseInitializerMode.EMBEDDED; private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
public String getSchema() { public String getSchema() {
return this.schema; return this.schema;
...@@ -58,11 +58,11 @@ public class IntegrationProperties { ...@@ -58,11 +58,11 @@ public class IntegrationProperties {
this.schema = schema; this.schema = schema;
} }
public DatabaseInitializerMode getInitializeSchema() { public DatabaseInitializationMode getInitializeSchema() {
return this.initializeSchema; return this.initializeSchema;
} }
public void setInitializeSchema(DatabaseInitializerMode initializeSchema) { public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
this.initializeSchema = initializeSchema; this.initializeSchema = initializeSchema;
} }
......
...@@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; ...@@ -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.DataSourceInitializerPostProcessor.Registrar;
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Condition;
......
...@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException; ...@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.context.EnvironmentAware; import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.Assert; import org.springframework.util.Assert;
......
...@@ -20,6 +20,7 @@ import javax.annotation.PreDestroy; ...@@ -20,6 +20,7 @@ import javax.annotation.PreDestroy;
import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
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.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
......
...@@ -21,8 +21,8 @@ import java.util.Map; ...@@ -21,8 +21,8 @@ import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.Database;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.quartz; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.quartz;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -41,7 +41,7 @@ public class QuartzDatabaseInitializer extends AbstractDatabaseInitializer { ...@@ -41,7 +41,7 @@ public class QuartzDatabaseInitializer extends AbstractDatabaseInitializer {
} }
@Override @Override
protected DatabaseInitializerMode getMode() { protected DatabaseInitializationMode getMode() {
return this.properties.getJdbc().getInitializeSchema(); return this.properties.getJdbc().getInitializeSchema();
} }
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.quartz; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.quartz;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -71,9 +71,9 @@ public class QuartzProperties { ...@@ -71,9 +71,9 @@ public class QuartzProperties {
private String schema = DEFAULT_SCHEMA_LOCATION; private String schema = DEFAULT_SCHEMA_LOCATION;
/** /**
* Quartz Scheduler database schema initialization mode. * Database schema initialization mode.
*/ */
private DatabaseInitializerMode initializeSchema = DatabaseInitializerMode.EMBEDDED; private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
public String getSchema() { public String getSchema() {
return this.schema; return this.schema;
...@@ -83,11 +83,11 @@ public class QuartzProperties { ...@@ -83,11 +83,11 @@ public class QuartzProperties {
this.schema = schema; this.schema = schema;
} }
public DatabaseInitializerMode getInitializeSchema() { public DatabaseInitializationMode getInitializeSchema() {
return this.initializeSchema; return this.initializeSchema;
} }
public void setInitializeSchema(DatabaseInitializerMode initializeSchema) { public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
this.initializeSchema = initializeSchema; this.initializeSchema = initializeSchema;
} }
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.session; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.session;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer; import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -41,7 +41,7 @@ public class JdbcSessionDatabaseInitializer extends AbstractDatabaseInitializer ...@@ -41,7 +41,7 @@ public class JdbcSessionDatabaseInitializer extends AbstractDatabaseInitializer
} }
@Override @Override
protected DatabaseInitializerMode getMode() { protected DatabaseInitializationMode getMode() {
return this.properties.getInitializeSchema(); return this.properties.getInitializeSchema();
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.session; package org.springframework.boot.autoconfigure.session;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -44,9 +44,9 @@ public class JdbcSessionProperties { ...@@ -44,9 +44,9 @@ public class JdbcSessionProperties {
private String tableName = DEFAULT_TABLE_NAME; private String tableName = DEFAULT_TABLE_NAME;
/** /**
* Spring Session database schema initialization mode. * Database schema initialization mode.
*/ */
private DatabaseInitializerMode initializeSchema = DatabaseInitializerMode.EMBEDDED; private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
public String getSchema() { public String getSchema() {
return this.schema; return this.schema;
...@@ -64,11 +64,11 @@ public class JdbcSessionProperties { ...@@ -64,11 +64,11 @@ public class JdbcSessionProperties {
this.tableName = tableName; this.tableName = tableName;
} }
public DatabaseInitializerMode getInitializeSchema() { public DatabaseInitializationMode getInitializeSchema() {
return this.initializeSchema; return this.initializeSchema;
} }
public void setInitializeSchema(DatabaseInitializerMode initializeSchema) { public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
this.initializeSchema = initializeSchema; this.initializeSchema = initializeSchema;
} }
......
...@@ -47,7 +47,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana ...@@ -47,7 +47,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
...@@ -89,7 +89,7 @@ public class BatchAutoConfigurationTests { ...@@ -89,7 +89,7 @@ public class BatchAutoConfigurationTests {
assertThat(context).hasSingleBean(JobExplorer.class); assertThat(context).hasSingleBean(JobExplorer.class);
assertThat( assertThat(
context.getBean(BatchProperties.class).getInitializeSchema()) context.getBean(BatchProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.EMBEDDED); .isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(new JdbcTemplate(context.getBean(DataSource.class)) assertThat(new JdbcTemplate(context.getBean(DataSource.class))
.queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty();
}); });
...@@ -176,7 +176,7 @@ public class BatchAutoConfigurationTests { ...@@ -176,7 +176,7 @@ public class BatchAutoConfigurationTests {
assertThat(context).hasSingleBean(JobLauncher.class); assertThat(context).hasSingleBean(JobLauncher.class);
assertThat( assertThat(
context.getBean(BatchProperties.class).getInitializeSchema()) context.getBean(BatchProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.NEVER); .isEqualTo(DatabaseInitializationMode.NEVER);
this.expected.expect(BadSqlGrammarException.class); this.expected.expect(BadSqlGrammarException.class);
new JdbcTemplate(context.getBean(DataSource.class)) new JdbcTemplate(context.getBean(DataSource.class))
.queryForList("select * from BATCH_JOB_EXECUTION"); .queryForList("select * from BATCH_JOB_EXECUTION");
...@@ -215,7 +215,7 @@ public class BatchAutoConfigurationTests { ...@@ -215,7 +215,7 @@ public class BatchAutoConfigurationTests {
assertThat(context).hasSingleBean(JobLauncher.class); assertThat(context).hasSingleBean(JobLauncher.class);
assertThat( assertThat(
context.getBean(BatchProperties.class).getInitializeSchema()) context.getBean(BatchProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.EMBEDDED); .isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(new JdbcTemplate(context.getBean(DataSource.class)) assertThat(new JdbcTemplate(context.getBean(DataSource.class))
.queryForList("select * from PREFIX_JOB_EXECUTION")) .queryForList("select * from PREFIX_JOB_EXECUTION"))
.isEmpty(); .isEmpty();
......
...@@ -27,7 +27,7 @@ import org.springframework.batch.core.explore.JobExplorer; ...@@ -27,7 +27,7 @@ import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRepository;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.test.City; import org.springframework.boot.autoconfigure.orm.jpa.test.City;
...@@ -69,7 +69,7 @@ public class BatchAutoConfigurationWithoutJpaTests { ...@@ -69,7 +69,7 @@ public class BatchAutoConfigurationWithoutJpaTests {
.contains("DataSourceTransactionManager"); .contains("DataSourceTransactionManager");
assertThat( assertThat(
context.getBean(BatchProperties.class).getInitializeSchema()) context.getBean(BatchProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.EMBEDDED); .isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(new JdbcTemplate(context.getBean(DataSource.class)) assertThat(new JdbcTemplate(context.getBean(DataSource.class))
.queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty();
assertThat(context.getBean(JobExplorer.class) assertThat(context.getBean(JobExplorer.class)
......
...@@ -26,7 +26,7 @@ import org.junit.Rule; ...@@ -26,7 +26,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
...@@ -155,7 +155,7 @@ public class IntegrationAutoConfigurationTests { ...@@ -155,7 +155,7 @@ public class IntegrationAutoConfigurationTests {
"spring.datasource.generate-unique-name=true", "spring.datasource.generate-unique-name=true",
"spring.integration.jdbc.initialize-schema=always"); "spring.integration.jdbc.initialize-schema=always");
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
.getInitializeSchema()).isEqualTo(DatabaseInitializerMode.ALWAYS); .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.ALWAYS);
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
assertThat(jdbcOperations.queryForList("select * from INT_MESSAGE")).isEmpty(); assertThat(jdbcOperations.queryForList("select * from INT_MESSAGE")).isEmpty();
assertThat(jdbcOperations.queryForList("select * from INT_GROUP_TO_MESSAGE")) assertThat(jdbcOperations.queryForList("select * from INT_GROUP_TO_MESSAGE"))
...@@ -175,7 +175,7 @@ public class IntegrationAutoConfigurationTests { ...@@ -175,7 +175,7 @@ public class IntegrationAutoConfigurationTests {
"spring.datasource.generate-unique-name=true", "spring.datasource.generate-unique-name=true",
"spring.integration.jdbc.initialize-schema=never"); "spring.integration.jdbc.initialize-schema=never");
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
.getInitializeSchema()).isEqualTo(DatabaseInitializerMode.NEVER); .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.NEVER);
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
this.thrown.expect(BadSqlGrammarException.class); this.thrown.expect(BadSqlGrammarException.class);
jdbcOperations.queryForList("select * from INT_MESSAGE"); jdbcOperations.queryForList("select * from INT_MESSAGE");
...@@ -188,7 +188,7 @@ public class IntegrationAutoConfigurationTests { ...@@ -188,7 +188,7 @@ public class IntegrationAutoConfigurationTests {
JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class }, JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class },
"spring.datasource.generate-unique-name=true"); "spring.datasource.generate-unique-name=true");
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc() assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
.getInitializeSchema()).isEqualTo(DatabaseInitializerMode.EMBEDDED); .getInitializeSchema()).isEqualTo(DatabaseInitializationMode.EMBEDDED);
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class); JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
jdbcOperations.queryForList("select * from INT_MESSAGE").isEmpty(); jdbcOperations.queryForList("select * from INT_MESSAGE").isEmpty();
} }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.jdbc; package org.springframework.boot.autoconfigure.jdbc;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Driver; import java.sql.Driver;
import java.sql.DriverPropertyInfo; import java.sql.DriverPropertyInfo;
...@@ -39,6 +41,7 @@ import org.springframework.beans.factory.BeanCreationException; ...@@ -39,6 +41,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.jdbc.DatabaseDriver; 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.HidePackagesClassLoader;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
...@@ -81,16 +84,11 @@ public class DataSourceAutoConfigurationTests { ...@@ -81,16 +84,11 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testBadUrl() throws Exception { public void testBadUrl() throws Exception {
try { this.contextRunner
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE; .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
this.contextRunner .withClassLoader(new DisableEmbeddedDatabaseClassLoader())
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") .run((context) -> assertThat(context).getFailure()
.run((context) -> assertThat(context).getFailure() .isInstanceOf(BeanCreationException.class));
.isInstanceOf(BeanCreationException.class));
}
finally {
EmbeddedDatabaseConnection.override = null;
}
} }
@Test @Test
...@@ -311,4 +309,24 @@ public class DataSourceAutoConfigurationTests { ...@@ -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);
}
}
} }
...@@ -68,7 +68,6 @@ public class DataSourceInitializerTests { ...@@ -68,7 +68,6 @@ public class DataSourceInitializerTests {
@Before @Before
public void init() { public void init() {
EmbeddedDatabaseConnection.override = null;
TestPropertyValues.of("spring.datasource.initialize:false", TestPropertyValues.of("spring.datasource.initialize:false",
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt()) "spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt())
.applyTo(this.context); .applyTo(this.context);
...@@ -76,7 +75,6 @@ public class DataSourceInitializerTests { ...@@ -76,7 +75,6 @@ public class DataSourceInitializerTests {
@After @After
public void restore() { public void restore() {
EmbeddedDatabaseConnection.override = null;
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
......
...@@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.jdbc; ...@@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.jdbc;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
......
...@@ -45,7 +45,6 @@ public class HikariDataSourceConfigurationTests { ...@@ -45,7 +45,6 @@ public class HikariDataSourceConfigurationTests {
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
EmbeddedDatabaseConnection.override = null;
} }
@Test @Test
......
...@@ -23,7 +23,6 @@ import javax.sql.DataSource; ...@@ -23,7 +23,6 @@ import javax.sql.DataSource;
import org.apache.tomcat.jdbc.pool.DataSourceProxy; import org.apache.tomcat.jdbc.pool.DataSourceProxy;
import org.apache.tomcat.jdbc.pool.PoolProperties; import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport; import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -56,11 +55,6 @@ public class TomcatDataSourceConfigurationTests { ...@@ -56,11 +55,6 @@ public class TomcatDataSourceConfigurationTests {
TestPropertyValues.of(PREFIX + "initialize:false").applyTo(this.context); TestPropertyValues.of(PREFIX + "initialize:false").applyTo(this.context);
} }
@After
public void restore() {
EmbeddedDatabaseConnection.override = null;
}
@Test @Test
public void testDataSourceExists() throws Exception { public void testDataSourceExists() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class); this.context.register(TomcatDataSourceConfiguration.class);
......
...@@ -107,8 +107,7 @@ public class QuartzAutoConfigurationTests { ...@@ -107,8 +107,7 @@ public class QuartzAutoConfigurationTests {
load(new Class<?>[] { QuartzJobsConfiguration.class, load(new Class<?>[] { QuartzJobsConfiguration.class,
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class }, DataSourceTransactionManagerAutoConfiguration.class },
"spring.quartz.job-store-type=jdbc", "spring.quartz.job-store-type=jdbc");
"spring.quartz.jdbc.initialize-schema=always");
testWithDataSource(); testWithDataSource();
} }
...@@ -116,8 +115,7 @@ public class QuartzAutoConfigurationTests { ...@@ -116,8 +115,7 @@ public class QuartzAutoConfigurationTests {
public void withDataSourceNoTransactionManager() throws Exception { public void withDataSourceNoTransactionManager() throws Exception {
load(new Class<?>[] { QuartzJobsConfiguration.class, load(new Class<?>[] { QuartzJobsConfiguration.class,
EmbeddedDataSourceConfiguration.class }, EmbeddedDataSourceConfiguration.class },
"spring.quartz.job-store-type=jdbc", "spring.quartz.job-store-type=jdbc");
"spring.quartz.jdbc.initialize-schema=always");
testWithDataSource(); testWithDataSource();
} }
......
...@@ -23,7 +23,7 @@ import org.junit.Test; ...@@ -23,7 +23,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.DatabaseInitializerMode; import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
...@@ -57,7 +57,7 @@ public class SessionAutoConfigurationJdbcTests ...@@ -57,7 +57,7 @@ public class SessionAutoConfigurationJdbcTests
.isEqualTo("SPRING_SESSION"); .isEqualTo("SPRING_SESSION");
assertThat( assertThat(
this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) this.context.getBean(JdbcSessionProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.EMBEDDED); .isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(this.context.getBean(JdbcOperations.class) assertThat(this.context.getBean(JdbcOperations.class)
.queryForList("select * from SPRING_SESSION")).isEmpty(); .queryForList("select * from SPRING_SESSION")).isEmpty();
} }
...@@ -74,7 +74,7 @@ public class SessionAutoConfigurationJdbcTests ...@@ -74,7 +74,7 @@ public class SessionAutoConfigurationJdbcTests
.isEqualTo("SPRING_SESSION"); .isEqualTo("SPRING_SESSION");
assertThat( assertThat(
this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) this.context.getBean(JdbcSessionProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.NEVER); .isEqualTo(DatabaseInitializationMode.NEVER);
this.thrown.expect(BadSqlGrammarException.class); this.thrown.expect(BadSqlGrammarException.class);
assertThat(this.context.getBean(JdbcOperations.class) assertThat(this.context.getBean(JdbcOperations.class)
.queryForList("select * from SPRING_SESSION")).isEmpty(); .queryForList("select * from SPRING_SESSION")).isEmpty();
...@@ -93,7 +93,7 @@ public class SessionAutoConfigurationJdbcTests ...@@ -93,7 +93,7 @@ public class SessionAutoConfigurationJdbcTests
.isEqualTo("FOO_BAR"); .isEqualTo("FOO_BAR");
assertThat( assertThat(
this.context.getBean(JdbcSessionProperties.class).getInitializeSchema()) this.context.getBean(JdbcSessionProperties.class).getInitializeSchema())
.isEqualTo(DatabaseInitializerMode.EMBEDDED); .isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(this.context.getBean(JdbcOperations.class) assertThat(this.context.getBean(JdbcOperations.class)
.queryForList("select * from FOO_BAR")).isEmpty(); .queryForList("select * from FOO_BAR")).isEmpty();
} }
......
...@@ -132,7 +132,7 @@ content into your application; rather pick only the properties that you need. ...@@ -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]) # QUARTZ SCHEDULER ({sc-spring-boot-autoconfigure}/quartz/QuartzProperties.{sc-ext}[QuartzProperties])
spring.quartz.job-store-type=memory # Quartz job store type. spring.quartz.job-store-type=memory # Quartz job store type.
spring.quartz.properties.*= # Additional Quartz Scheduler properties. spring.quartz.properties.*= # Additional Quartz Scheduler properties.
spring.quartz.jdbc.initialize-schema=embedded # Quartz Scheduler database schema initialization mode. 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. 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 # Reactor
...@@ -416,7 +416,7 @@ content into your application; rather pick only the properties that you need. ...@@ -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 ({sc-spring-boot-autoconfigure}/session/SessionProperties.{sc-ext}[SessionProperties])
spring.session.hazelcast.flush-mode=on-save # Sessions flush mode. 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.hazelcast.map-name=spring:session:sessions # Name of the map used to store sessions.
spring.session.jdbc.initialize-schema=embedded # Spring Session database schema initialization mode. 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.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.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions.
spring.session.redis.flush-mode=on-save # Sessions flush mode. 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. ...@@ -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.artemis.user= # Login user of the broker.
# SPRING BATCH ({sc-spring-boot-autoconfigure}/batch/BatchProperties.{sc-ext}[BatchProperties]) # SPRING BATCH ({sc-spring-boot-autoconfigure}/batch/BatchProperties.{sc-ext}[BatchProperties])
spring.batch.initialize-schema=embedded # Spring Batch database schema initialization mode. 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.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.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.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.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 ({sc-spring-boot-autoconfigure}/integration/IntegrationProperties.{sc-ext}[IntegrationProperties])
spring.integration.jdbc.initialize-schema=embedded # Spring Integration database schema initialization mode. 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. 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]) # JMS ({sc-spring-boot-autoconfigure}/jms/JmsProperties.{sc-ext}[JmsProperties])
......
...@@ -1935,12 +1935,16 @@ data. ...@@ -1935,12 +1935,16 @@ data.
[[howto-initialize-a-spring-batch-database]] [[howto-initialize-a-spring-batch-database]]
=== 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 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 for most popular database platforms. Spring Boot can detect your database type and
execute those scripts by default when using an embedded database, and in this case will execute those scripts on startup. If you are using an embedded database this happens
switch the fail fast setting to false (errors are logged but do not prevent the by default. You can also enable it for any database type:
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 [indent=0,subs="verbatim,quotes,attributes"]
scripts idempotent. You can switch off the initialization explicitly using ----
spring.batch.initialize-schema=always
----
You can also switch off the initialization explicitly using
`spring.batch.initialize-schema=never`. `spring.batch.initialize-schema=never`.
......
...@@ -26,7 +26,7 @@ import java.lang.annotation.Target; ...@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 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.PropertyMapping;
import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping; import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping;
......
...@@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; ...@@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 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.EnvironmentAware;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
......
...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
......
...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
......
...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
......
...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith; ...@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.context.annotation.Configuration;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
......
...@@ -24,7 +24,7 @@ import org.junit.Test; ...@@ -24,7 +24,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.autoconfigure.jdbc; package org.springframework.boot.jdbc;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -109,11 +109,6 @@ public enum EmbeddedDatabaseConnection { ...@@ -109,11 +109,6 @@ public enum EmbeddedDatabaseConnection {
return String.format(this.url, databaseName); 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 * Convenience method to determine if a given driver class name represents an embedded
* database type. * database type.
...@@ -149,9 +144,6 @@ public enum EmbeddedDatabaseConnection { ...@@ -149,9 +144,6 @@ public enum EmbeddedDatabaseConnection {
* @return an {@link EmbeddedDatabaseConnection} or {@link #NONE}. * @return an {@link EmbeddedDatabaseConnection} or {@link #NONE}.
*/ */
public static EmbeddedDatabaseConnection get(ClassLoader classLoader) { public static EmbeddedDatabaseConnection get(ClassLoader classLoader) {
if (override != null) {
return override;
}
for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) { for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) {
if (candidate != NONE && ClassUtils.isPresent(candidate.getDriverClassName(), if (candidate != NONE && ClassUtils.isPresent(candidate.getDriverClassName(),
classLoader)) { classLoader)) {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.autoconfigure.jdbc; package org.springframework.boot.jdbc;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment