You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DataSource configuration is controlled by external configuration properties in `+spring.datasource.*+`.
4105
4094
For example, you might declare the following section in `application.properties`:
4106
4095
@@ -4119,12 +4108,11 @@ Otherwise, Spring Boot tries to auto-configure an embedded database.
4119
4108
TIP: Spring Boot can deduce the JDBC driver class for most databases from the URL.
4120
4109
If you need to specify a specific class, you can use the configprop:spring.datasource.driver-class-name[] property.
4121
4110
4122
-
4123
4111
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.
4124
4112
In other words, if you set `spring.datasource.driver-class-name=com.mysql.jdbc.Driver`, then that class has to be loadable.
4125
4113
4126
4114
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>>.
4128
4116
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.*+`).
4129
4117
Refer to the documentation of the connection pool implementation you are using for more details.
4130
4118
@@ -4144,6 +4132,35 @@ This will set the pool to wait 10000 ms before throwing an exception if no conne
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
+
4147
4164
[[boot-features-connecting-to-a-jndi-datasource]]
4148
4165
==== Connection to a JNDI DataSource
4149
4166
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