Documentation improvement of DataSource configuration
Closes gh-2126
This commit is contained in:
@@ -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
|
||||
<<spring-boot-features.adoc#boot-features-external-config-3rd-party-configuration>>, e.g.
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
|
||||
@@ -571,6 +571,28 @@ TIP: Using `@ConfigurationProperties` also allows you to generate meta-data file
|
||||
be used by IDEs. See the <<configuration-metadata>> 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`.
|
||||
|
||||
Reference in New Issue
Block a user