From 3da108fdda088b9ed741a413d9cb05fb181c42f2 Mon Sep 17 00:00:00 2001 From: slaws Date: Sat, 4 Jul 2009 07:37:12 +0000 Subject: TUSCANY-3128 - force the bean factory classloader to be the contribution classloader as it's reset by the application context on refresh. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@791072 13f79535-47bb-0310-9956-ffa450edef68 --- .../spring/runtime/context/SpringContextTie.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'branches/sca-java-1.x') diff --git a/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java index 5961c52cc4..d53edf2325 100644 --- a/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java +++ b/branches/sca-java-1.x/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java @@ -36,8 +36,10 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.GenericApplicationContext; @@ -57,6 +59,28 @@ public class SpringContextTie { private boolean isAnnotationSupported; private String versionSupported; + // TUSCANY-3128 + // extension of the generic application context just to force the classloader + // on the bean factory to stay set to the contribution classloader + // instead of being set back to the application classloader + private class LocalGenericApplicationContext extends GenericApplicationContext{ + + ClassLoader classloader = null; + + public LocalGenericApplicationContext(DefaultListableBeanFactory beanFactory, + ApplicationContext parent, + ClassLoader classloader) { + super(beanFactory, parent); + this.classloader = classloader; + } + + @Override + protected void postProcessBeanFactory( + ConfigurableListableBeanFactory beanFactory) { + beanFactory.setBeanClassLoader(classloader); + } + } + public SpringContextTie(SpringImplementationStub implementation, URL resource, boolean annotationSupport, String versionSupported) throws Exception { this.implementation = implementation; this.isAnnotationSupported = annotationSupport; @@ -134,8 +158,13 @@ public class SpringContextTie { // use the generic application context as default if (isAnnotationSupported) + { includeAnnotationProcessors(beanFactory); - appContext = new GenericApplicationContext(beanFactory, scaParentContext); + } + + appContext = new LocalGenericApplicationContext(beanFactory, + scaParentContext, + implementation.getClassLoader()); return appContext; } -- cgit v1.2.3