parent
d2e55a2038
commit
db3c7a157e
|
|
@ -48,7 +48,7 @@ To configure a `DriverManagerDataSource`:
|
||||||
|
|
||||||
The following example shows how to configure a `DriverManagerDataSource`:
|
The following example shows how to configure a `DriverManagerDataSource`:
|
||||||
|
|
||||||
include-code::./DriverManagerDataSourceConfiguration[tag=dataSourceBean,indent=0]
|
include-code::./DriverManagerDataSourceConfiguration[tag=snippet,indent=0]
|
||||||
|
|
||||||
The next two examples show the basic connectivity and configuration for DBCP and C3P0.
|
The next two examples show the basic connectivity and configuration for DBCP and C3P0.
|
||||||
To learn about more options that help control the pooling features, see the product
|
To learn about more options that help control the pooling features, see the product
|
||||||
|
|
@ -56,11 +56,11 @@ documentation for the respective connection pooling implementations.
|
||||||
|
|
||||||
The following example shows DBCP configuration:
|
The following example shows DBCP configuration:
|
||||||
|
|
||||||
include-code::./BasicDataSourceConfiguration[tag=dataSourceBean,indent=0]
|
include-code::./BasicDataSourceConfiguration[tag=snippet,indent=0]
|
||||||
|
|
||||||
The following example shows C3P0 configuration:
|
The following example shows C3P0 configuration:
|
||||||
|
|
||||||
include-code::./ComboPooledDataSourceConfiguration[tag=dataSourceBean,indent=0]
|
include-code::./ComboPooledDataSourceConfiguration[tag=snippet,indent=0]
|
||||||
|
|
||||||
[[jdbc-DataSourceUtils]]
|
[[jdbc-DataSourceUtils]]
|
||||||
== Using `DataSourceUtils`
|
== Using `DataSourceUtils`
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Configuration
|
@Configuration
|
||||||
class BasicDataSourceConfiguration {
|
class BasicDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean(destroyMethod = "close")
|
@Bean(destroyMethod = "close")
|
||||||
BasicDataSource dataSource() {
|
BasicDataSource dataSource() {
|
||||||
BasicDataSource dataSource = new BasicDataSource();
|
BasicDataSource dataSource = new BasicDataSource();
|
||||||
|
|
@ -34,6 +34,6 @@ class BasicDataSourceConfiguration {
|
||||||
dataSource.setPassword("");
|
dataSource.setPassword("");
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Configuration
|
@Configuration
|
||||||
class ComboPooledDataSourceConfiguration {
|
class ComboPooledDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean(destroyMethod = "close")
|
@Bean(destroyMethod = "close")
|
||||||
ComboPooledDataSource dataSource() throws PropertyVetoException {
|
ComboPooledDataSource dataSource() throws PropertyVetoException {
|
||||||
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
||||||
|
|
@ -35,6 +35,6 @@ class ComboPooledDataSourceConfiguration {
|
||||||
dataSource.setPassword("");
|
dataSource.setPassword("");
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
@Configuration
|
@Configuration
|
||||||
class DriverManagerDataSourceConfiguration {
|
class DriverManagerDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean
|
@Bean
|
||||||
DriverManagerDataSource dataSource() {
|
DriverManagerDataSource dataSource() {
|
||||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||||
|
|
@ -33,6 +33,6 @@ class DriverManagerDataSourceConfiguration {
|
||||||
dataSource.setPassword("");
|
dataSource.setPassword("");
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration
|
||||||
@Configuration
|
@Configuration
|
||||||
class BasicDataSourceConfiguration {
|
class BasicDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean(destroyMethod = "close")
|
@Bean(destroyMethod = "close")
|
||||||
fun dataSource() = BasicDataSource().apply {
|
fun dataSource() = BasicDataSource().apply {
|
||||||
driverClassName = "org.hsqldb.jdbcDriver"
|
driverClassName = "org.hsqldb.jdbcDriver"
|
||||||
|
|
@ -15,5 +15,5 @@ class BasicDataSourceConfiguration {
|
||||||
username = "sa"
|
username = "sa"
|
||||||
password = ""
|
password = ""
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration
|
||||||
@Configuration
|
@Configuration
|
||||||
internal class ComboPooledDataSourceConfiguration {
|
internal class ComboPooledDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean(destroyMethod = "close")
|
@Bean(destroyMethod = "close")
|
||||||
fun dataSource() = ComboPooledDataSource().apply {
|
fun dataSource() = ComboPooledDataSource().apply {
|
||||||
driverClass = "org.hsqldb.jdbcDriver"
|
driverClass = "org.hsqldb.jdbcDriver"
|
||||||
|
|
@ -15,6 +15,6 @@ internal class ComboPooledDataSourceConfiguration {
|
||||||
user = "sa"
|
user = "sa"
|
||||||
password = ""
|
password = ""
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource
|
||||||
@Configuration
|
@Configuration
|
||||||
class DriverManagerDataSourceConfiguration {
|
class DriverManagerDataSourceConfiguration {
|
||||||
|
|
||||||
// tag::dataSourceBean[]
|
// tag::snippet[]
|
||||||
@Bean
|
@Bean
|
||||||
fun dataSource() = DriverManagerDataSource().apply {
|
fun dataSource() = DriverManagerDataSource().apply {
|
||||||
setDriverClassName("org.hsqldb.jdbcDriver")
|
setDriverClassName("org.hsqldb.jdbcDriver")
|
||||||
|
|
@ -31,6 +31,6 @@ class DriverManagerDataSourceConfiguration {
|
||||||
username = "sa"
|
username = "sa"
|
||||||
password = ""
|
password = ""
|
||||||
}
|
}
|
||||||
// end::dataSourceBean[]
|
// end::snippet[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:context="http://www.springframework.org/schema/context">
|
xmlns:context="http://www.springframework.org/schema/context">
|
||||||
|
|
||||||
<!-- tag::dataSourceBean[] -->
|
<!-- tag::snippet[] -->
|
||||||
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
|
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
|
||||||
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
||||||
<property name="url" value="${jdbc.url}"/>
|
<property name="url" value="${jdbc.url}"/>
|
||||||
|
|
@ -11,5 +11,5 @@
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<context:property-placeholder location="jdbc.properties"/>
|
<context:property-placeholder location="jdbc.properties"/>
|
||||||
<!-- end::dataSourceBean[] -->
|
<!-- end::snippet[] -->
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:context="http://www.springframework.org/schema/context">
|
xmlns:context="http://www.springframework.org/schema/context">
|
||||||
|
|
||||||
<!-- tag::dataSourceBean[] -->
|
<!-- tag::snippet[] -->
|
||||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
|
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
|
||||||
<property name="driverClass" value="${jdbc.driverClassName}"/>
|
<property name="driverClass" value="${jdbc.driverClassName}"/>
|
||||||
<property name="jdbcUrl" value="${jdbc.url}"/>
|
<property name="jdbcUrl" value="${jdbc.url}"/>
|
||||||
|
|
@ -11,5 +11,5 @@
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<context:property-placeholder location="jdbc.properties"/>
|
<context:property-placeholder location="jdbc.properties"/>
|
||||||
<!-- end::dataSourceBean[] -->
|
<!-- end::snippet[] -->
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:context="http://www.springframework.org/schema/context">
|
xmlns:context="http://www.springframework.org/schema/context">
|
||||||
|
|
||||||
<!-- tag::dataSourceBean[] -->
|
<!-- tag::snippet[] -->
|
||||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||||
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
||||||
<property name="url" value="${jdbc.url}"/>
|
<property name="url" value="${jdbc.url}"/>
|
||||||
|
|
@ -11,5 +11,5 @@
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<context:property-placeholder location="jdbc.properties"/>
|
<context:property-placeholder location="jdbc.properties"/>
|
||||||
<!-- end::dataSourceBean[] -->
|
<!-- end::snippet[] -->
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue