T - the DataSource type being builtpublic final class DataSourceBuilder<T extends javax.sql.DataSource>
extends java.lang.Object
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:
com.zaxxer.hikari.HikariDataSource)org.apache.tomcat.jdbc.pool.DataSource)org.apache.commons.dbcp2.BasicDataSource)oracle.ucp.jdbc.PoolDataSourceImpl)
The following non-pooling DataSource implementations can be used when
explicitly set as a type:
SimpleDriverDataSource
(org.springframework.jdbc.datasource.SimpleDriverDataSource)oracle.jdbc.datasource.OracleDataSource)org.h2.jdbcx.JdbcDataSource)org.postgresql.ds.PGSimpleDataSource)DataSource implementation with appropriately named methods
This class is commonly used in an @Bean method and often combined with
@ConfigurationProperties.
create(),
create(ClassLoader),
derivedFrom(DataSource)| Modifier and Type | Method and Description |
|---|---|
T |
build()
Return a newly built
DataSource instance. |
static DataSourceBuilder<?> |
create()
Create a new
DataSourceBuilder instance. |
static DataSourceBuilder<?> |
create(java.lang.ClassLoader classLoader)
Create a new
DataSourceBuilder instance. |
static DataSourceBuilder<?> |
derivedFrom(javax.sql.DataSource dataSource)
Create a new
DataSourceBuilder instance derived from the specified data
source. |
DataSourceBuilder<T> |
driverClassName(java.lang.String driverClassName)
Set the driver class name that should be used when building the datasource.
|
static java.lang.Class<? extends javax.sql.DataSource> |
findType(java.lang.ClassLoader classLoader)
Find the
DataSource type preferred for the given classloader. |
DataSourceBuilder<T> |
password(java.lang.String password)
Set the password that should be used when building the datasource.
|
<D extends javax.sql.DataSource> |
type(java.lang.Class<D> type)
Set the
DataSource type that should be built. |
DataSourceBuilder<T> |
url(java.lang.String url)
Set the URL that should be used when building the datasource.
|
DataSourceBuilder<T> |
username(java.lang.String username)
Set the username that should be used when building the datasource.
|
public <D extends javax.sql.DataSource> DataSourceBuilder<D> type(java.lang.Class<D> type)
DataSource type that should be built.D - the datasource typetype - the datasource typepublic DataSourceBuilder<T> url(java.lang.String url)
url - the JDBC urlpublic DataSourceBuilder<T> driverClassName(java.lang.String driverClassName)
driverClassName - the driver class namepublic DataSourceBuilder<T> username(java.lang.String username)
username - the user namepublic DataSourceBuilder<T> password(java.lang.String password)
password - the passwordpublic T build()
DataSource instance.public static DataSourceBuilder<?> create()
DataSourceBuilder instance.public static DataSourceBuilder<?> create(java.lang.ClassLoader classLoader)
DataSourceBuilder instance.classLoader - the classloader used to discover preferred settingsDataSource builder instancepublic static DataSourceBuilder<?> derivedFrom(javax.sql.DataSource dataSource)
DataSourceBuilder instance derived from the specified data
source. The returned builder can be used to build the same type of
DataSource with username, password, url and
driverClassName properties copied from the original when not specifically
set.dataSource - the source DataSourceDataSource builderpublic static java.lang.Class<? extends javax.sql.DataSource> findType(java.lang.ClassLoader classLoader)
DataSource type preferred for the given classloader.classLoader - the classloader used to discover preferred settingsDataSource type