类 DataSourceBuilder<T extends DataSource>
java.lang.Object
org.springframework.boot.jdbc.DataSourceBuilder<T>
- 类型参数:
T- theDataSourcetype being built
Convenience class for building a
DataSource. Provides a limited subset of the
properties supported by a typical DataSource as well as detection logic to pick
the most suitable pooling DataSource implementation.
The following pooling DataSource implementations are supported by this builder.
When no type has been explicitly set, the first available pool
implementation will be picked:
- Hikari (
com.zaxxer.hikari.HikariDataSource) - Tomcat JDBC Pool (
org.apache.tomcat.jdbc.pool.DataSource) - Apache DBCP2 (
org.apache.commons.dbcp2.BasicDataSource) - Oracle UCP (
oracle.ucp.jdbc.PoolDataSourceImpl) - C3P0 (
com.mchange.v2.c3p0.ComboPooledDataSource)
The following non-pooling DataSource implementations can be used when
explicitly set as a type:
- Spring's
SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) - Oracle (
oracle.jdbc.datasource.OracleDataSource) - H2 (
org.h2.jdbcx.JdbcDataSource) - Postgres (
org.postgresql.ds.PGSimpleDataSource) - Any
DataSourceimplementation with appropriately named methods
This class is commonly used in an @Bean method and often combined with
@ConfigurationProperties.
- 从以下版本开始:
- 2.0.0
- 作者:
- Dave Syer, Madhura Bhave, Fabio Grassi, Phillip Webb
- 另请参阅:
-
方法概要
修饰符和类型方法说明build()Return a newly builtDataSourceinstance.static DataSourceBuilder<?> create()Create a newDataSourceBuilderinstance.static DataSourceBuilder<?> create(ClassLoader classLoader) Create a newDataSourceBuilderinstance.static DataSourceBuilder<?> derivedFrom(DataSource dataSource) Create a newDataSourceBuilderinstance derived from the specified data source.driverClassName(String driverClassName) Set the driver class name that should be used when building the datasource.static Class<? extends DataSource> findType(ClassLoader classLoader) Find theDataSourcetype preferred for the given classloader.Set the password that should be used when building the datasource.<D extends DataSource>
DataSourceBuilder<D> Set theDataSourcetype that should be built.Set the URL that should be used when building the datasource.Set the username that should be used when building the datasource.
-
方法详细资料
-
type
Set theDataSourcetype that should be built.- 类型参数:
D- the datasource type- 参数:
type- the datasource type- 返回:
- this builder
-
url
Set the URL that should be used when building the datasource.- 参数:
url- the JDBC url- 返回:
- this builder
-
driverClassName
Set the driver class name that should be used when building the datasource.- 参数:
driverClassName- the driver class name- 返回:
- this builder
-
username
Set the username that should be used when building the datasource.- 参数:
username- the user name- 返回:
- this builder
-
password
Set the password that should be used when building the datasource.- 参数:
password- the password- 返回:
- this builder
-
build
Return a newly builtDataSourceinstance.- 返回:
- the built datasource
-
create
Create a newDataSourceBuilderinstance.- 返回:
- a new datasource builder instance
-
create
Create a newDataSourceBuilderinstance.- 参数:
classLoader- the classloader used to discover preferred settings- 返回:
- a new
DataSourcebuilder instance
-
derivedFrom
Create a newDataSourceBuilderinstance derived from the specified data source. The returned builder can be used to build the same type ofDataSourcewithusername,password,urlanddriverClassNameproperties copied from the original when not specifically set.- 参数:
dataSource- the sourceDataSource- 返回:
- a new
DataSourcebuilder - 从以下版本开始:
- 2.5.0
-
findType
Find theDataSourcetype preferred for the given classloader.- 参数:
classLoader- the classloader used to discover preferred settings- 返回:
- the preferred
DataSourcetype
-