parent
d2e55a2038
commit
db3c7a157e
|
@ -48,7 +48,7 @@ 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.
|
||||
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:
|
||||
|
||||
include-code::./BasicDataSourceConfiguration[tag=dataSourceBean,indent=0]
|
||||
include-code::./BasicDataSourceConfiguration[tag=snippet,indent=0]
|
||||
|
||||
The following example shows C3P0 configuration:
|
||||
|
||||
include-code::./ComboPooledDataSourceConfiguration[tag=dataSourceBean,indent=0]
|
||||
include-code::./ComboPooledDataSourceConfiguration[tag=snippet,indent=0]
|
||||
|
||||
[[jdbc-DataSourceUtils]]
|
||||
== Using `DataSourceUtils`
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
@Configuration
|
||||
class BasicDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean(destroyMethod = "close")
|
||||
BasicDataSource dataSource() {
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
|
@ -34,6 +34,6 @@ class BasicDataSourceConfiguration {
|
|||
dataSource.setPassword("");
|
||||
return dataSource;
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
@Configuration
|
||||
class ComboPooledDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean(destroyMethod = "close")
|
||||
ComboPooledDataSource dataSource() throws PropertyVetoException {
|
||||
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
||||
|
@ -35,6 +35,6 @@ class ComboPooledDataSourceConfiguration {
|
|||
dataSource.setPassword("");
|
||||
return dataSource;
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|||
@Configuration
|
||||
class DriverManagerDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
DriverManagerDataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
|
@ -33,6 +33,6 @@ class DriverManagerDataSourceConfiguration {
|
|||
dataSource.setPassword("");
|
||||
return dataSource;
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration
|
|||
@Configuration
|
||||
class BasicDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean(destroyMethod = "close")
|
||||
fun dataSource() = BasicDataSource().apply {
|
||||
driverClassName = "org.hsqldb.jdbcDriver"
|
||||
|
@ -15,5 +15,5 @@ class BasicDataSourceConfiguration {
|
|||
username = "sa"
|
||||
password = ""
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration
|
|||
@Configuration
|
||||
internal class ComboPooledDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean(destroyMethod = "close")
|
||||
fun dataSource() = ComboPooledDataSource().apply {
|
||||
driverClass = "org.hsqldb.jdbcDriver"
|
||||
|
@ -15,6 +15,6 @@ internal class ComboPooledDataSourceConfiguration {
|
|||
user = "sa"
|
||||
password = ""
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource
|
|||
@Configuration
|
||||
class DriverManagerDataSourceConfiguration {
|
||||
|
||||
// tag::dataSourceBean[]
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun dataSource() = DriverManagerDataSource().apply {
|
||||
setDriverClassName("org.hsqldb.jdbcDriver")
|
||||
|
@ -31,6 +31,6 @@ class DriverManagerDataSourceConfiguration {
|
|||
username = "sa"
|
||||
password = ""
|
||||
}
|
||||
// end::dataSourceBean[]
|
||||
// end::snippet[]
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context">
|
||||
|
||||
<!-- tag::dataSourceBean[] -->
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
||||
<property name="url" value="${jdbc.url}"/>
|
||||
|
@ -11,5 +11,5 @@
|
|||
</bean>
|
||||
|
||||
<context:property-placeholder location="jdbc.properties"/>
|
||||
<!-- end::dataSourceBean[] -->
|
||||
<!-- end::snippet[] -->
|
||||
</beans>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context">
|
||||
|
||||
<!-- tag::dataSourceBean[] -->
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
|
||||
<property name="driverClass" value="${jdbc.driverClassName}"/>
|
||||
<property name="jdbcUrl" value="${jdbc.url}"/>
|
||||
|
@ -11,5 +11,5 @@
|
|||
</bean>
|
||||
|
||||
<context:property-placeholder location="jdbc.properties"/>
|
||||
<!-- end::dataSourceBean[] -->
|
||||
<!-- end::snippet[] -->
|
||||
</beans>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context">
|
||||
|
||||
<!-- tag::dataSourceBean[] -->
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
||||
<property name="url" value="${jdbc.url}"/>
|
||||
|
@ -11,5 +11,5 @@
|
|||
</bean>
|
||||
|
||||
<context:property-placeholder location="jdbc.properties"/>
|
||||
<!-- end::dataSourceBean[] -->
|
||||
<!-- end::snippet[] -->
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue