diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java index 2c0f5cdb..6e8c8090 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java @@ -29,9 +29,11 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.ResolvableType; import org.springframework.core.env.MapPropertySource; @@ -45,6 +47,7 @@ import org.springframework.core.env.MapPropertySource; * @param specification * @author Spencer Gibb * @author Dave Syer + * @author Tommy Karlsson */ // TODO: add javadoc public abstract class NamedContextFactory @@ -110,7 +113,25 @@ public abstract class NamedContextFactory configuration : this.configurations.get(name).getConfiguration()) { context.register(configuration); @@ -129,9 +150,6 @@ public abstract class NamedContextFactory { + Thread t = new Thread(r); + t.setContextClassLoader(new ThrowingClassLoader()); + return t; + }); + + es.submit(() -> this.testChildContexts(parent)).get(5, TimeUnit.SECONDS); + } + private TestSpec getSpec(String name, Class configClass) { return new TestSpec(name, new Class[] { configClass }); } + static class ThrowingClassLoader extends ClassLoader { + + ThrowingClassLoader() { + super(null); + } + + @Override + public Class loadClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException(name); + } + + } + static class TestClientFactory extends NamedContextFactory { TestClientFactory() { @@ -147,6 +193,7 @@ public class NamedContextFactoryTests { } + @ConditionalOnClass(Object.class) static class FooConfig { @Bean