Document spring.datasource.name

The `spring.datasource.name` property was hidden behind the 'name'
attribute of the Tomcat connection pool (since we are mapping all
datasource implementations on the `spring.datasource` namespace.

This commit replace the injected value by hand with the use of the
regular `DataSourceProperties`. That way, we generate proper meta-data
for it as well.

Closes gh-3755
This commit is contained in:
Stephane Nicoll 2015-08-14 14:07:38 +02:00
parent 2d62e1fc89
commit d1a4d6958a
3 changed files with 21 additions and 5 deletions

View File

@ -42,6 +42,11 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
public static final String PREFIX = "spring.datasource";
/**
* Name of the datasource.
*/
private String name = "testdb";
/**
* Fully qualified name of the connection pool implementation to use. By default,
* it is auto-detected from the classpath.
@ -126,6 +131,14 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
.get(this.classLoader);
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Class<? extends DataSource> getType() {
return type;
}

View File

@ -19,7 +19,8 @@ package org.springframework.boot.autoconfigure.jdbc;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
@ -29,17 +30,19 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
* Configuration for embedded data sources.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @see DataSourceAutoConfiguration
*/
@Configuration
@EnableConfigurationProperties(DataSourceProperties.class)
public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
private EmbeddedDatabase database;
private ClassLoader classLoader;
@Value("${spring.datasource.name:testdb}")
private String name = "testdb";
@Autowired
private DataSourceProperties properties;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
@ -50,7 +53,7 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
public EmbeddedDatabase dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseConnection.get(this.classLoader).getType());
this.database = builder.setName(this.name).build();
this.database = builder.setName(this.properties.getName()).build();
return this.database;
}

View File

@ -310,7 +310,7 @@ content into your application; rather pick only the properties that you need.
security.oauth2.sso.login-path= # Path to the login page, i.e. the one that triggers the redirect to the OAuth2 Authorization Server
# DATASOURCE ({sc-spring-boot-autoconfigure}/jdbc/DataSourceAutoConfiguration.{sc-ext}[DataSourceAutoConfiguration] & {sc-spring-boot-autoconfigure}/jdbc/DataSourceProperties.{sc-ext}[DataSourceProperties])
spring.datasource.name= # name of the data source
spring.datasource.name=testdb # name of the data source
spring.datasource.initialize=true # populate using data.sql
spring.datasource.schema= # a schema (DDL) script resource reference
spring.datasource.data= # a data (DML) script resource reference