-
Notifications
You must be signed in to change notification settings - Fork 120
DBCP Configuration
Vlad Mihalcea edited this page Oct 17, 2024
·
6 revisions
<dependency>
<groupId>com.vladmihalcea.flexy-pool</groupId>
<artifactId>flexy-dbcp</artifactId>
<version>${flexy-pool.version}</version>
</dependency>
ext {
flexypoolVersion = 124
}
dependencies {
compile "com.vladmihalcea.flexy-pool:flexy-dbcp:${flexypoolVersion}"
}
<bean id="poolingDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxActive" value="3"/>
<property name="maxWait" value="1000"/>
</bean>
@org.springframework.context.annotation.Configuration
public class FlexyPoolBeanConfiguration {
@Autowired
private BasicDataSource poolingDataSource;
@Value("${flexy.pool.uniqueId}")
private String uniqueId;
@Bean
public FlexyPoolConfiguration<BasicDataSource> configuration() {
return new FlexyPoolConfiguration.Builder<BasicDataSource>(
uniqueId,
poolingDataSource,
DBCPPoolAdapter.FACTORY
).build();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
FlexyPoolConfiguration<BasicDataSource> configuration = configuration();
return new FlexyPoolDataSource<BasicDataSource>(configuration,
new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
new RetryConnectionAcquisitionStrategy.Factory(2)
);
}
}
<bean id="configurationBuilder" class="com.vladmihalcea.flexypool.config.Configuration$Builder">
<constructor-arg value="uniqueId"/>
<constructor-arg ref="poolingDataSource"/>
<constructor-arg value="#{ T(com.vladmihalcea.flexypool.adaptor.DBCPPoolAdapter).FACTORY }"/>
</bean>
<bean id="configuration" factory-bean="configurationBuilder" factory-method="build"/>
<bean id="dataSource" class="com.vladmihalcea.flexypool.FlexyPoolDataSource" init-method="start" destroy-method="stop">
<constructor-arg ref="configuration"/>
<constructor-arg>
<array>
<bean class="com.vladmihalcea.flexypool.strategy.IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory">
<constructor-arg value="5"/>
</bean>
<bean class="com.vladmihalcea.flexypool.strategy.RetryConnectionAcquisitionStrategy.Factory">
<constructor-arg value="2"/>
</bean>
</array>
</constructor-arg>
</bean>