Skip to content

Commit 9aa1ce2

Browse files
committed
Document DataSource implementations supported by DataSourceBuilder
Closes gh-25333
1 parent c66db58 commit 9aa1ce2

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,22 +4085,11 @@ Disabling the database's automatic shutdown lets Spring Boot control when the da
40854085
[[boot-features-connect-to-production-database]]
40864086
==== Connection to a Production Database
40874087
Production database connections can also be auto-configured by using a pooling `DataSource`.
4088-
Spring Boot uses the following algorithm for choosing a specific implementation:
4089-
4090-
. We prefer https://github.com/brettwooldridge/HikariCP[HikariCP] for its performance and concurrency.
4091-
If HikariCP is available, we always choose it.
4092-
. Otherwise, if the Tomcat pooling `DataSource` is available, we use it.
4093-
. Otherwise, if https://commons.apache.org/proper/commons-dbcp/[Commons DBCP2] is available, we use it.
4094-
. If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, we use it.
40954088

4096-
If you use the `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa` "`starters`", you automatically get a dependency to `HikariCP`.
40974089

4098-
NOTE: You can bypass that algorithm completely and specify the connection pool to use by setting the configprop:spring.datasource.type[] property.
4099-
This is especially important if you run your application in a Tomcat container, as `tomcat-jdbc` is provided by default.
4100-
4101-
TIP: Additional connection pools can always be configured manually.
4102-
If you define your own `DataSource` bean, auto-configuration does not occur.
41034090

4091+
[[boot-features-connect-to-production-database-configuration]]
4092+
==== DataSource Configuration
41044093
DataSource configuration is controlled by external configuration properties in `+spring.datasource.*+`.
41054094
For example, you might declare the following section in `application.properties`:
41064095

@@ -4119,12 +4108,11 @@ Otherwise, Spring Boot tries to auto-configure an embedded database.
41194108
TIP: Spring Boot can deduce the JDBC driver class for most databases from the URL.
41204109
If you need to specify a specific class, you can use the configprop:spring.datasource.driver-class-name[] property.
41214110

4122-
41234111
NOTE: For a pooling `DataSource` to be created, we need to be able to verify that a valid `Driver` class is available, so we check for that before doing anything.
41244112
In other words, if you set `spring.datasource.driver-class-name=com.mysql.jdbc.Driver`, then that class has to be loadable.
41254113

41264114
See {spring-boot-autoconfigure-module-code}/jdbc/DataSourceProperties.java[`DataSourceProperties`] for more of the supported options.
4127-
These are the standard options that work regardless of the actual implementation.
4115+
These are the standard options that work regardless of <<boot-features-connect-to-production-database-connection-pool, the actual implementation>>.
41284116
It is also possible to fine-tune implementation-specific settings by using their respective prefix (`+spring.datasource.hikari.*+`, `+spring.datasource.tomcat.*+`, `+spring.datasource.dbcp2.*+`, and `+spring.datasource.oracleucp.*+`).
41294117
Refer to the documentation of the connection pool implementation you are using for more details.
41304118

@@ -4144,6 +4132,35 @@ This will set the pool to wait 10000 ms before throwing an exception if no conne
41444132

41454133

41464134

4135+
[[boot-features-connect-to-production-database-connection-pool]]
4136+
==== Supported Connection Pools
4137+
Spring Boot uses the following algorithm for choosing a specific implementation:
4138+
4139+
. We prefer https://github.com/brettwooldridge/HikariCP[HikariCP] for its performance and concurrency.
4140+
If HikariCP is available, we always choose it.
4141+
. Otherwise, if the Tomcat pooling `DataSource` is available, we use it.
4142+
. Otherwise, if https://commons.apache.org/proper/commons-dbcp/[Commons DBCP2] is available, we use it.
4143+
. If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, we use it.
4144+
4145+
NOTE: If you use the `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa` "`starters`", you automatically get a dependency to `HikariCP`.
4146+
4147+
You can bypass that algorithm completely and specify the connection pool to use by setting the configprop:spring.datasource.type[] property.
4148+
This is especially important if you run your application in a Tomcat container, as `tomcat-jdbc` is provided by default.
4149+
4150+
Additional connection pools can always be configured manually, using `DataSourceBuilder`.
4151+
If you define your own `DataSource` bean, auto-configuration does not occur.
4152+
The following connection pools are supported by `DataSourceBuilder`:
4153+
4154+
* HikariCP
4155+
* Tomcat pooling `Datasource`
4156+
* Commons DBCP2
4157+
* Orale UCP & `OracleDataSource`
4158+
* Spring Framework's `SimpleDriverDataSource`
4159+
* H2 `JdbcDataSource`
4160+
* PostgreSQL `PGSimpleDataSource`
4161+
4162+
4163+
41474164
[[boot-features-connecting-to-a-jndi-datasource]]
41484165
==== Connection to a JNDI DataSource
41494166
If you deploy your Spring Boot application to an Application Server, you might want to configure and manage your DataSource by using your Application Server's built-in features and access it by using JNDI.

0 commit comments

Comments
 (0)