From 1b039e78e655c80f562a99a5686b3b3815c613d2 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 17 Dec 2014 14:25:33 +0100 Subject: [PATCH] Documentation improvement of DataSource configuration Closes gh-2126 --- spring-boot-docs/src/main/asciidoc/howto.adoc | 3 +- .../main/asciidoc/spring-boot-features.adoc | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index b271786b37..8797c49ab5 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1103,7 +1103,8 @@ samples for more detail and to see it in action. To override the default settings just define a `@Bean` of your own of type `DataSource`. Spring Boot provides a utility builder class `DataSourceBuilder` that can be used to create one of the standard ones (if it is on the classpath), or you can just create -your own, and bind it to a set of `Environment` properties e.g. +your own, and bind it to a set of `Environment` properties as explained in +<>, e.g. [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index d158658f2b..001c329e2e 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -571,6 +571,28 @@ TIP: Using `@ConfigurationProperties` also allows you to generate meta-data file be used by IDEs. See the <> appendix for details. +[[boot-features-external-config-3rd-party-configuration]] +==== Third-party configuration + +You can also use that feature for third-party components: in that case, you can't obviously +add a `@ConfigurationProperties` to it if you don't have access to the source code or if that +component does not know about Spring Boot. + +To configure a bean from the `Environment` properties, add `@ConfigurationProperties` to its +bean registration: + +[source,java,indent=0] +---- + + @ConfigurationProperties(prefix = "foo") + @Bean + public FooComponent fooComponent() { + ... + } +---- + +Any property defined with the `foo` prefix will be mapped onto that `FooComponent` bean in a +similar manner as the `ConnectionSettings` example above. [[boot-features-external-config-relaxed-binding]] ==== Relaxed binding @@ -1416,7 +1438,7 @@ Production database connections can also be auto-configured using a pooling * Lastly, if Commons DBCP2 is available we will use it If you use the `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa` -'`starter POMs`' you will automcatically get a dependency to `tomcat-jdbc`. +'`starter POMs`' you will automatically get a dependency to `tomcat-jdbc`. NOTE: Additional connection pools can always be configured manually. If you define your own `DataSource` bean, auto-configuration will not occur. @@ -1434,7 +1456,9 @@ in `application.properties`: ---- See {sc-spring-boot-autoconfigure}/jdbc/DataSourceProperties.{sc-ext}[`DataSourceProperties`] -for more of the supported options. +for more of the supported options. Note also that you can configure any of the `DataSource` +implementation specific properties via `+spring.datasource.*+`: refer to the documentation +of the connection pool implementation you are using for more details. TIP: You often won't need to specify the `driver-class-name` since Spring boot can deduce it for most databases from the `url`.