diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java index 2fc71144a0..62bf5cb4b5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.util.StringUtils; * * @author Dave Syer */ -@ConfigurationProperties(name = "spring.datasource") +@ConfigurationProperties(name = DataSourceAutoConfiguration.CONFIGURATION_PREFIX) @EnableConfigurationProperties public abstract class AbstractDataSourceConfiguration implements BeanClassLoaderAware { 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 6d717347cf..0d1b4574a5 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 @@ -69,6 +69,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware { private static Log logger = LogFactory.getLog(DataSourceAutoConfiguration.class); + public static final String CONFIGURATION_PREFIX = "spring.datasource"; + @Autowired(required = false) private DataSource dataSource; @@ -79,7 +81,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware { @Override public void setEnvironment(Environment environment) { - this.environment = new RelaxedPropertyResolver(environment, "spring.database."); + this.environment = new RelaxedPropertyResolver(environment, CONFIGURATION_PREFIX + + "."); } @PostConstruct @@ -218,7 +221,7 @@ public class DataSourceAutoConfiguration implements EnvironmentAware { private String getDriverClassName(Environment environment, ClassLoader classLoader) { String driverClassName = environment == null ? null : environment - .getProperty("spring.database.driverClassName"); + .getProperty(CONFIGURATION_PREFIX + ".driverClassName"); if (driverClassName == null) { driverClassName = EmbeddedDatabaseConnection.get(classLoader) .getDriverClassName(); @@ -228,7 +231,7 @@ public class DataSourceAutoConfiguration implements EnvironmentAware { private String getUrl(Environment environment, ClassLoader classLoader) { String url = (environment == null ? null : environment - .getProperty("spring.database.url")); + .getProperty(CONFIGURATION_PREFIX + ".url")); if (url == null) { url = EmbeddedDatabaseConnection.get(classLoader).getUrl(); } 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 dd3e885558..cc0426fad6 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 @@ -101,7 +101,7 @@ public class DataSourceAutoConfigurationTests { this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); Map map = new HashMap(); - map.put("spring.database.schema", + map.put(DataSourceAutoConfiguration.CONFIGURATION_PREFIX + ".schema", ClassUtils.addResourcePathToPackagePath(getClass(), "schema.sql")); this.context.getEnvironment().getPropertySources() .addFirst(new MapPropertySource("test", map)); @@ -119,7 +119,7 @@ public class DataSourceAutoConfigurationTests { this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); Map map = new HashMap(); - map.put("spring.database.schema", + map.put(DataSourceAutoConfiguration.CONFIGURATION_PREFIX + ".schema", ClassUtils.addResourcePathToPackagePath(getClass(), "schema.sql") + "," + ClassUtils.addResourcePathToPackagePath(getClass(),