Fix bug in datasource autoconfiguration
The AbstractDataSourceConfiguration had path= in its @ConfigurationProperties by mistake (should have been value)
This commit is contained in:
parent
5d7101fb5a
commit
759aa785a7
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc;
|
|||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -26,7 +27,8 @@ import org.springframework.util.StringUtils;
|
|||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ConfigurationProperties(path = "spring.datasource")
|
||||
@ConfigurationProperties(name = "spring.datasource")
|
||||
@EnableConfigurationProperties
|
||||
public abstract class AbstractDataSourceConfiguration implements BeanClassLoaderAware {
|
||||
|
||||
private String driverClassName;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ import javax.sql.DataSource;
|
|||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.TestUtils;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +50,17 @@ public class TomcatDataSourceConfigurationTests {
|
|||
this.context.register(TomcatDataSourceConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertNotNull(this.context.getBean(DataSource.class));
|
||||
assertNotNull(this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSourcePropertiesOverridden() throws Exception {
|
||||
this.context.register(TomcatDataSourceConfiguration.class);
|
||||
TestUtils.addEnviroment(this.context, "spring.datasource.url:jdbc:foo//bar/spam");
|
||||
this.context.refresh();
|
||||
assertEquals("jdbc:foo//bar/spam",
|
||||
this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class)
|
||||
.getUrl());
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector {
|
|||
public String[] selectImports(AnnotationMetadata metadata) {
|
||||
MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(
|
||||
EnableConfigurationProperties.class.getName(), false);
|
||||
Object[] type = (Object[]) attributes.getFirst("value");
|
||||
Object[] type = attributes == null ? null : (Object[]) attributes
|
||||
.getFirst("value");
|
||||
if (type == null || type.length == 0) {
|
||||
return new String[] { ConfigurationPropertiesBindingPostProcessorRegistrar.class
|
||||
.getName() };
|
||||
|
|
|
|||
Loading…
Reference in New Issue