Standardize on spring.datasource.* for database config

[Fixes #58921238] [bs-333] spring.database.* and
spring.datasource.* used to configure database
pull/95/head
Dave Syer 11 years ago
parent ea11dafcbd
commit acf458b462

@ -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 {

@ -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();
}

@ -101,7 +101,7 @@ public class DataSourceAutoConfigurationTests {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
Map<String, Object> map = new HashMap<String, Object>();
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<String, Object> map = new HashMap<String, Object>();
map.put("spring.database.schema",
map.put(DataSourceAutoConfiguration.CONFIGURATION_PREFIX + ".schema",
ClassUtils.addResourcePathToPackagePath(getClass(), "schema.sql")
+ ","
+ ClassUtils.addResourcePathToPackagePath(getClass(),

Loading…
Cancel
Save