diff --git a/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java b/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java index b61c3900..df939400 100644 --- a/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java +++ b/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java @@ -219,6 +219,8 @@ public class ContextSourceParser implements BeanDefinitionParser { builder.addPropertyValue("maxWait", getInt(poolingElement, ATT_MAX_WAIT, DEFAULT_MAX_WAIT)); String whenExhausted = getString(poolingElement, ATT_WHEN_EXHAUSTED, PoolExhaustedAction.BLOCK.name()); builder.addPropertyValue("whenExhaustedAction", PoolExhaustedAction.valueOf(whenExhausted).getValue()); + builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(poolingElement, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); + builder.addPropertyValue("minEvictableIdleTimeMillis", getString(poolingElement, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); boolean testOnBorrow = getBoolean(poolingElement, ATT_TEST_ON_BORROW, false); boolean testOnReturn = getBoolean(poolingElement, ATT_TEST_ON_RETURN, false); @@ -249,9 +251,9 @@ public class ContextSourceParser implements BeanDefinitionParser { } builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition()); - builder.addPropertyValue("timeBetweenEvictionRunsMillis", getInt(element, ATT_EVICTION_RUN_MILLIS, DEFAULT_EVICTION_RUN_MILLIS)); + builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); builder.addPropertyValue("numTestsPerEvictionRun", getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN)); - builder.addPropertyValue("minEvictableIdleTimeMillis", getInt(element, ATT_EVICTABLE_TIME_MILLIS, DEFAULT_EVICTABLE_MILLIS)); + builder.addPropertyValue("minEvictableIdleTimeMillis", getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS, CommunicationException.class.getName()); String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions); @@ -316,9 +318,9 @@ public class ContextSourceParser implements BeanDefinitionParser { configBuilder.addPropertyValue("testOnCreate", getBoolean(element, ATT_TEST_ON_CREATE, false)); configBuilder.addPropertyValue("testOnReturn", getBoolean(element, ATT_TEST_ON_RETURN, false)); configBuilder.addPropertyValue("testWhileIdle", getBoolean(element, ATT_TEST_WHILE_IDLE, false)); - configBuilder.addPropertyValue("timeBetweenEvictionRunsMillis", getInt(element, ATT_EVICTION_RUN_MILLIS, DEFAULT_EVICTION_RUN_MILLIS)); + configBuilder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); configBuilder.addPropertyValue("numTestsPerEvictionRun", getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN)); - configBuilder.addPropertyValue("minEvictableIdleTimeMillis", getInt(element, ATT_EVICTABLE_TIME_MILLIS, DEFAULT_EVICTABLE_MILLIS)); + configBuilder.addPropertyValue("minEvictableIdleTimeMillis", getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); configBuilder.addPropertyValue("softMinEvictableIdleTimeMillis", getInt(element, ATT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); builder.addConstructorArgValue(configBuilder.getBeanDefinition()); diff --git a/core/src/main/resources/org/springframework/ldap/config/spring-ldap-2.0.xsd b/core/src/main/resources/org/springframework/ldap/config/spring-ldap-2.0.xsd index 492e3559..7d264720 100644 --- a/core/src/main/resources/org/springframework/ldap/config/spring-ldap-2.0.xsd +++ b/core/src/main/resources/org/springframework/ldap/config/spring-ldap-2.0.xsd @@ -206,7 +206,7 @@ - + The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, @@ -222,7 +222,7 @@ - + The minimum amount of time an object may sit idle in the pool before it is eligible @@ -347,7 +347,7 @@ - + The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, @@ -363,7 +363,7 @@ - + The minimum amount of time an object may sit idle in the pool before it is eligible @@ -682,4 +682,4 @@ - \ No newline at end of file + diff --git a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java index 2b2901bf..a831a31f 100644 --- a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java @@ -494,4 +494,33 @@ public class LdapTemplateNamespaceHandlerTest { public void verifyParseWithPool1AndPool2WillFail() { new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml"); } + + @Test + public void verifyParsePoolWithPlaceholders() { + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-config-with-placeholders.xml"); + ContextSource outerContextSource = ctx.getBean(ContextSource.class); + assertNotNull(outerContextSource); + + ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); + assertNotNull(pooledContextSource); + + GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); + assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis()); + assertEquals(20, objectPool.getMinEvictableIdleTimeMillis()); + } + + @Test + public void verifyParsePool2WithPlaceholders() { + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-config-with-placeholders.xml"); + ContextSource outerContextSource = ctx.getBean(ContextSource.class); + assertNotNull(outerContextSource); + + ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); + assertNotNull(pooledContextSource); + + org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = + (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); + assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis()); + assertEquals(20, objectPool.getMinEvictableIdleTimeMillis()); + } } diff --git a/core/src/test/resources/ldap-namespace-config-pooling-config-with-placeholders.xml b/core/src/test/resources/ldap-namespace-config-pooling-config-with-placeholders.xml new file mode 100644 index 00000000..125329a2 --- /dev/null +++ b/core/src/test/resources/ldap-namespace-config-pooling-config-with-placeholders.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/ldap-namespace-config-pooling2-config-with-placeholders.xml b/core/src/test/resources/ldap-namespace-config-pooling2-config-with-placeholders.xml new file mode 100644 index 00000000..0e6523ac --- /dev/null +++ b/core/src/test/resources/ldap-namespace-config-pooling2-config-with-placeholders.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/core/src/test/resources/ldap.properties b/core/src/test/resources/ldap.properties new file mode 100644 index 00000000..0cc6cd15 --- /dev/null +++ b/core/src/test/resources/ldap.properties @@ -0,0 +1,2 @@ +ldap.eviction.run.internal.milis=10 +ldap.min.evictable.time.milis=20 \ No newline at end of file