Support Property Placeholders in XML Configuration

Fixes gh-370
This commit is contained in:
Eddú Meléndez
2016-02-18 22:36:00 +10:00
committed by Rob Winch
parent dd8c62b6ba
commit 1ffd11acd8
6 changed files with 72 additions and 9 deletions

View File

@@ -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());
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath*:ldap.properties" />
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"/>
</ldap:context-source>
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath*:ldap.properties" />
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2 eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"/>
</ldap:context-source>
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,2 @@
ldap.eviction.run.internal.milis=10
ldap.min.evictable.time.milis=20