Package org.springframework.boot.jdbc
Class DataSourceBuilder<T extends DataSource>
java.lang.Object
org.springframework.boot.jdbc.DataSourceBuilder<T>
- Type Parameters:
- T- the- DataSourcetype 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.
- Since:
- 2.0.0
- Author:
- Dave Syer, Madhura Bhave, Fabio Grassi, Phillip Webb
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionbuild()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.
- 
Method Details- 
typeSet theDataSourcetype that should be built.- Type Parameters:
- D- the datasource type
- Parameters:
- type- the datasource type
- Returns:
- this builder
 
- 
urlSet the URL that should be used when building the datasource.- Parameters:
- url- the JDBC url
- Returns:
- this builder
 
- 
driverClassNameSet the driver class name that should be used when building the datasource.- Parameters:
- driverClassName- the driver class name
- Returns:
- this builder
 
- 
usernameSet the username that should be used when building the datasource.- Parameters:
- username- the user name
- Returns:
- this builder
 
- 
passwordSet the password that should be used when building the datasource.- Parameters:
- password- the password
- Returns:
- this builder
 
- 
buildReturn a newly builtDataSourceinstance.- Returns:
- the built datasource
 
- 
createCreate a newDataSourceBuilderinstance.- Returns:
- a new datasource builder instance
 
- 
createCreate a newDataSourceBuilderinstance.- Parameters:
- classLoader- the classloader used to discover preferred settings
- Returns:
- a new DataSourcebuilder instance
 
- 
derivedFromCreate 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.- Parameters:
- dataSource- the source- DataSource
- Returns:
- a new DataSourcebuilder
- Since:
- 2.5.0
 
- 
findTypeFind theDataSourcetype preferred for the given classloader.- Parameters:
- classLoader- the classloader used to discover preferred settings
- Returns:
- the preferred DataSourcetype
 
 
-