diff --git a/build.gradle b/build.gradle
index 316a0f7c70e..395cea4c298 100644
--- a/build.gradle
+++ b/build.gradle
@@ -405,6 +405,7 @@ project("spring-aop") {
compile("aopalliance:aopalliance:1.0")
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("commons-pool:commons-pool:1.6")
+ optional("org.apache.commons:commons-pool2:2.2")
optional("com.jamonapi:jamon:2.79")
}
}
@@ -463,6 +464,7 @@ project("spring-context") {
optional("org.jruby:jruby:1.7.17")
testCompile("javax.inject:javax.inject-tck:1")
testCompile("commons-dbcp:commons-dbcp:1.4")
+ testCompile("org.apache.commons:commons-pool2:2.2")
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
index 261d1cab604..f24b22df596 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
* @see org.springframework.aop.target.SingletonTargetSource
* @see org.springframework.aop.target.LazyInitTargetSource
* @see org.springframework.aop.target.PrototypeTargetSource
- * @see org.springframework.aop.target.CommonsPoolTargetSource
+ * @see org.springframework.aop.target.CommonsPool2TargetSource
*/
public void setTarget(Object target) {
this.target = target;
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java
index dc37b8099f0..46d6fdbd607 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,19 +17,20 @@
package org.springframework.aop.framework.autoproxy.target;
import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
-import org.springframework.aop.target.CommonsPoolTargetSource;
+import org.springframework.aop.target.CommonsPool2TargetSource;
import org.springframework.aop.target.PrototypeTargetSource;
import org.springframework.aop.target.ThreadLocalTargetSource;
/**
* Convenient TargetSourceCreator using bean name prefixes to create one of three
* well-known TargetSource types:
- *
: CommonsPoolTargetSource
+ *
: CommonsPool2TargetSource
*
% ThreadLocalTargetSource
*
! PrototypeTargetSource
*
* @author Rod Johnson
- * @see org.springframework.aop.target.CommonsPoolTargetSource
+ * @author Stephane Nicoll
+ * @see org.springframework.aop.target.CommonsPool2TargetSource
* @see org.springframework.aop.target.ThreadLocalTargetSource
* @see org.springframework.aop.target.PrototypeTargetSource
*/
@@ -44,7 +45,7 @@ public class QuickTargetSourceCreator extends AbstractBeanFactoryBasedTargetSour
Class> beanClass, String beanName) {
if (beanName.startsWith(PREFIX_COMMONS_POOL)) {
- CommonsPoolTargetSource cpts = new CommonsPoolTargetSource();
+ CommonsPool2TargetSource cpts = new CommonsPool2TargetSource();
cpts.setMaxSize(25);
return cpts;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
index b21cc4ba1a0..56f618171c6 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ import org.springframework.util.ObjectUtils;
* @see LazyInitTargetSource
* @see PrototypeTargetSource
* @see ThreadLocalTargetSource
- * @see CommonsPoolTargetSource
+ * @see CommonsPool2TargetSource
*/
public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSource, BeanFactoryAware, Serializable {
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java
index 63d8d6d2066..897c05aa37b 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.DisposableBean;
* implementations which maintain a pool of target instances, acquiring and
* releasing a target object from the pool for each method invocation.
* This abstract base class is independent of concrete pooling technology;
- * see the subclass {@link CommonsPoolTargetSource} for a concrete example.
+ * see the subclass {@link CommonsPool2TargetSource} for a concrete example.
*
*
Subclasses must implement the {@link #getTarget} and
* {@link #releaseTarget} methods based on their chosen object pool.
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java
index 24e0286e97f..415d0e57e12 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
* @see org.springframework.beans.factory.BeanFactory#getBean
* @see PrototypeTargetSource
* @see ThreadLocalTargetSource
- * @see CommonsPoolTargetSource
+ * @see CommonsPool2TargetSource
*/
@SuppressWarnings("serial")
public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFactoryBasedTargetSource {
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java
new file mode 100644
index 00000000000..4cc34dcf65a
--- /dev/null
+++ b/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java
@@ -0,0 +1,345 @@
+/*
+ * Copyright 2002-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.aop.target;
+
+import org.apache.commons.pool2.ObjectPool;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+
+/**
+ * {@link org.springframework.aop.TargetSource} implementation that holds
+ * objects in a configurable Apache Commons2 Pool.
+ *
+ *
By default, an instance of {@code GenericObjectPool} is created.
+ * Subclasses may change the type of {@code ObjectPool} used by
+ * overriding the {@code createObjectPool()} method.
+ *
+ *
Provides many configuration properties mirroring those of the Commons Pool
+ * {@code GenericObjectPool} class; these properties are passed to the
+ * {@code GenericObjectPool} during construction. If creating a subclass of this
+ * class to change the {@code ObjectPool} implementation type, pass in the values
+ * of configuration properties that are relevant to your chosen implementation.
+ *
+ *
The {@code testOnBorrow}, {@code testOnReturn} and {@code testWhileIdle}
+ * properties are explicitly not mirrored because the implementation of
+ * {@code PoolableObjectFactory} used by this class does not implement
+ * meaningful validation. All exposed Commons Pool properties use the
+ * corresponding Commons Pool defaults.
+ *
+ *
Commons Pool 2.x uses object equality while Commons Pool 1.x used identity
+ * equality. This clearly means that Commons Pool 2 behaves differently if several
+ * instances having the same identity according to their {@link Object#equals(Object)}
+ * method are managed in the same pool. To provide a smooth upgrade, a
+ * backward-compatible pool is created by default; use {@link #setUseObjectEquality(boolean)}
+ * if you need the standard Commons Pool 2.x behavior.
+ *
+ *