From ddc9bbb555ccb3d2164e77f0f13b554cc5f7c05b Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 6 May 2011 12:05:56 +0000 Subject: [PATCH] [SPR-6184] Simplifying ContextLoader implmementation: - Removed AbstractGenericContextLoader's createGenericApplicationContext() method. - AnnotationConfigContextLoader now uses an AnnotatedBeanDefinitionReader instead of working with an AnnotationConfigApplicationContext. - AnnotationConfigContextLoader now uses the supplied GenericApplicationContext to load configuration classes. --- .../test/context/ContextLoaderUtils.java | 2 +- .../ResourceTypeAwareContextLoader.java | 3 ++ .../support/AbstractGenericContextLoader.java | 40 ++++++------------- .../AnnotationConfigContextLoader.java | 38 ++++++------------ 4 files changed, 30 insertions(+), 53 deletions(-) diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java index 1e8c83a69fc..0ad20cec081 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java @@ -137,8 +137,8 @@ abstract class ContextLoaderUtils { } try { - ContextConfiguration contextConfiguration = clazz.getAnnotation(annotationType); if (logger.isTraceEnabled()) { + ContextConfiguration contextConfiguration = clazz.getAnnotation(annotationType); logger.trace("Using default ContextLoader class [" + defaultContextLoaderClassName + "] for @ContextConfiguration [" + contextConfiguration + "] and class [" + clazz + "]"); } diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java index 6c35da0750b..dd39037f9e3 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ResourceTypeAwareContextLoader.java @@ -25,6 +25,9 @@ package org.springframework.test.context; * resource locations; as of Spring 3.1 context loaders may choose to * support either String-based or Class-based resources (but not both). * + *

TODO Document how classes are converted into String[] locations + * and passed into the corresponding methods in the ContextLoader API. + * *

If a context loader does not implement this interface it is assumed * that the loader supports String-based resource locations. * diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index fc8bc886617..83867996eee 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -28,15 +28,17 @@ import org.springframework.util.StringUtils; /** * Abstract, generic extension of {@link AbstractContextLoader} which loads a * {@link GenericApplicationContext} from the locations provided to - * {@link #loadContext(String...)}. + * {@link #loadContext loadContext()}. * - *

Concrete subclasses must provide an appropriate - * {@link #createBeanDefinitionReader(GenericApplicationContext) BeanDefinitionReader}. + *

Concrete subclasses must provide an appropriate implementation of + * {@link #createBeanDefinitionReader createBeanDefinitionReader()}, + * potentially overriding {@link #loadBeanDefinitions loadBeanDefinitions()} + * in addition. * * @author Sam Brannen * @author Juergen Hoeller * @since 2.5 - * @see #loadContext(String...) + * @see #loadContext */ public abstract class AbstractGenericContextLoader extends AbstractContextLoader { @@ -47,8 +49,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader * Loads a Spring ApplicationContext from the supplied locations. *

Implementation details: *