diff --git a/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java b/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java index 9040c296..77271e7f 100644 --- a/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java +++ b/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.access.BeanFactoryReference; import org.springframework.beans.factory.wiring.BeanConfigurerSupport; import org.springframework.beans.factory.wiring.BeanWiringInfo; import org.springframework.beans.factory.wiring.BeanWiringInfoResolver; @@ -67,6 +68,8 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener // condition determining the initialization state of this Declarable volatile boolean initialized = false; + private BeanFactoryReference beanFactoryReference = null; + private String factoryKey = null; /** @@ -137,7 +140,7 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener protected void assertUninitialized() { Assert.state(!isInitialized(), String.format( "This Declarable object (%1$s) has already been configured and initialized", - getClass().getName())); + getClass().getName())); } /** @@ -261,7 +264,11 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener * @see org.springframework.beans.factory.BeanFactory */ protected BeanFactory locateBeanFactory(String factoryKey) { - return new GemfireBeanFactoryLocator().useBeanFactory(factoryKey).getFactory(); + if (beanFactoryReference == null) { + beanFactoryReference = new GemfireBeanFactoryLocator().useBeanFactory(factoryKey); + } + + return beanFactoryReference.getFactory(); } /** @@ -310,6 +317,7 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener @Override public void destroy() throws Exception { SpringContextBootstrappingInitializer.unregister(this); + beanFactoryReference.release(); parametersReference.set(null); initialized = false; } diff --git a/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java b/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java index 17f0f6b0..baf18c42 100644 --- a/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java +++ b/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java @@ -38,8 +38,11 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils; * @see org.springframework.beans.factory.wiring.BeanConfigurerSupport * @see org.springframework.beans.factory.wiring.BeanWiringInfo * @see org.springframework.data.gemfire.DeclarableSupport + * @see org.springframework.data.gemfire.LazyWiringDeclarableSupport * @see com.gemstone.gemfire.cache.Declarable + * @deprecated please use LazyWiringDeclarableSupport instead. */ +@Deprecated public class WiringDeclarableSupport extends DeclarableSupport { private static final String BEAN_NAME_PROPERTY = "bean-name";