[SPR-8387] refined logging for failed generation of defaults; polishing JavaDoc.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4625 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
01a490225f
commit
a19a8f5c6d
|
|
@ -30,7 +30,7 @@ import java.lang.annotation.Target;
|
||||||
* for test classes.
|
* for test classes.
|
||||||
*
|
*
|
||||||
* <p>Prior to Spring 3.1, only path-based resource locations were supported.
|
* <p>Prior to Spring 3.1, only path-based resource locations were supported.
|
||||||
* As of Spring 3.1 {@link #loader context loaders} may choose to support
|
* As of Spring 3.1, {@link #loader context loaders} may choose to support
|
||||||
* either path-based or class-based resources (but not both). Consequently
|
* either path-based or class-based resources (but not both). Consequently
|
||||||
* {@code @ContextConfiguration} can be used to declare either path-based
|
* {@code @ContextConfiguration} can be used to declare either path-based
|
||||||
* resource locations (via the {@link #locations} or {@link #value}
|
* resource locations (via the {@link #locations} or {@link #value}
|
||||||
|
|
@ -40,7 +40,9 @@ import java.lang.annotation.Target;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see ContextLoader
|
* @see ContextLoader
|
||||||
|
* @see SmartContextLoader
|
||||||
* @see org.springframework.context.ApplicationContext
|
* @see org.springframework.context.ApplicationContext
|
||||||
|
* @see ActiveProfiles
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
@Inherited
|
@Inherited
|
||||||
|
|
@ -62,20 +64,26 @@ public @interface ContextConfiguration {
|
||||||
* The resource locations to use for loading an
|
* The resource locations to use for loading an
|
||||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
||||||
*
|
*
|
||||||
* <p>Check out the javadoc for {@link org.springframework.test.context.support.AbstractContextLoader#modifyLocations AbstractContextLoader.modifyLocations()}
|
* <p>Check out the javadoc for
|
||||||
* for details on how a location String will be interpreted at runtime,
|
* {@link org.springframework.test.context.support.AbstractContextLoader#modifyLocations
|
||||||
* in particular in case of a relative path. Also, check out the documentation on
|
* AbstractContextLoader.modifyLocations()} for details on how a location
|
||||||
* {@link org.springframework.test.context.support.AbstractContextLoader#generateDefaultLocations AbstractContextLoader.generateDefaultLocations()}
|
* String will be interpreted at runtime, in particular in case of a relative
|
||||||
* for details on the default locations that are going to be used if none are specified.
|
* path. Also, check out the documentation on
|
||||||
|
* {@link org.springframework.test.context.support.AbstractContextLoader#generateDefaultLocations
|
||||||
|
* AbstractContextLoader.generateDefaultLocations()} for details on the default
|
||||||
|
* locations that are going to be used if none are specified.
|
||||||
*
|
*
|
||||||
* <p>Note that the above-mentioned default rules only apply for a standard
|
* <p>Note that the above-mentioned default rules only apply for a standard
|
||||||
* {@link org.springframework.test.context.support.AbstractContextLoader AbstractContextLoader} subclass
|
* {@link org.springframework.test.context.support.AbstractContextLoader
|
||||||
* such as {@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}
|
* AbstractContextLoader} subclass such as
|
||||||
* which is the effective default implementation used at runtime.
|
* {@link org.springframework.test.context.support.GenericXmlContextLoader
|
||||||
|
* GenericXmlContextLoader} which is the effective default implementation
|
||||||
|
* used at runtime.
|
||||||
*
|
*
|
||||||
* <p>This attribute may <strong>not</strong> be used in conjunction
|
* <p>This attribute may <strong>not</strong> be used in conjunction with
|
||||||
* with {@link #value} or {@link #classes}, but it may be used
|
* {@link #value} or {@link #classes}, but it may be used instead of
|
||||||
* instead of {@link #value}.
|
* {@link #value}.
|
||||||
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
String[] locations() default {};
|
String[] locations() default {};
|
||||||
|
|
||||||
|
|
@ -85,13 +93,15 @@ public @interface ContextConfiguration {
|
||||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
||||||
*
|
*
|
||||||
* <p>To enable support for configuration class processing, an appropriate
|
* <p>To enable support for configuration class processing, an appropriate
|
||||||
* {@link ContextLoader} must be {@link #loader configured}.
|
* {@link SmartContextLoader} must be {@link #loader configured}.
|
||||||
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader AnnotationConfigContextLoader}
|
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader
|
||||||
* is one such loader provided by the Spring Framework.
|
* AnnotationConfigContextLoader} is one such loader provided by the Spring Framework.
|
||||||
*
|
*
|
||||||
* <p>Check out the javadoc for
|
* <p>Check out the javadoc for
|
||||||
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#generateDefaultLocations AnnotationConfigContextLoader.generateDefaultLocations()}
|
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#generateDefaultConfigurationClasses
|
||||||
* for details on the default configuration classes that will be used if none are specified.
|
* AnnotationConfigContextLoader.generateDefaultConfigurationClasses()}
|
||||||
|
* for details on the default configuration classes that will be used if none
|
||||||
|
* are specified.
|
||||||
*
|
*
|
||||||
* <p>Note that this attribute may <strong>not</strong> be used in
|
* <p>Note that this attribute may <strong>not</strong> be used in
|
||||||
* conjunction with {@link #locations} or {@link #value}.
|
* conjunction with {@link #locations} or {@link #value}.
|
||||||
|
|
@ -158,22 +168,27 @@ public @interface ContextConfiguration {
|
||||||
* // ...
|
* // ...
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
boolean inheritLocations() default true;
|
boolean inheritLocations() default true;
|
||||||
|
|
||||||
|
// TODO Update regarding default --> DelegatingSmartContextLoader
|
||||||
/**
|
/**
|
||||||
* The type of {@link ContextLoader} to use for loading an
|
* The type of {@link ContextLoader} (or {@link SmartContextLoader}) to use
|
||||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
* for loading an {@link org.springframework.context.ApplicationContext
|
||||||
|
* ApplicationContext}.
|
||||||
*
|
*
|
||||||
* <p>If not specified, the loader will be inherited from the first superclass
|
* <p>If not specified, the loader will be inherited from the first superclass
|
||||||
* which is annotated with <code>@ContextConfiguration</code> and specifies
|
* that is annotated with {@code @ContextConfiguration} and specifies an
|
||||||
* an explicit loader. If no class in the hierarchy specifies an explicit
|
* explicit loader. If no class in the hierarchy specifies an explicit
|
||||||
* loader, a default loader will be used instead.
|
* loader, a default loader will be used instead.
|
||||||
*
|
*
|
||||||
* <p>The default concrete implementation chosen at runtime will be
|
* <p>The default concrete implementation chosen at runtime will be
|
||||||
* {@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}.
|
* {@link org.springframework.test.context.support.GenericXmlContextLoader
|
||||||
* Also check out {@link org.springframework.test.context.support.AbstractContextLoader AbstractContextLoader}'s
|
* GenericXmlContextLoader}. Also check out
|
||||||
* javadoc for details on the default behavior there.
|
* {@link org.springframework.test.context.support.AbstractContextLoader
|
||||||
|
* AbstractContextLoader}'s javadoc for details on the default behavior there.
|
||||||
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
Class<? extends ContextLoader> loader() default ContextLoader.class;
|
Class<? extends ContextLoader> loader() default ContextLoader.class;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,9 +143,10 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
|
||||||
String resourcePath = SLASH + ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix;
|
String resourcePath = SLASH + ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix;
|
||||||
|
|
||||||
if (!new ClassPathResource(resourcePath, clazz).exists()) {
|
if (!new ClassPathResource(resourcePath, clazz).exists()) {
|
||||||
logger.warn(String.format(
|
if (logger.isInfoEnabled()) {
|
||||||
"Cannot generate default resource location for test class [%s]: classpath resource [%s] does not exist.",
|
logger.info(String.format("Cannot generate default resource locations for test class [%s]: "
|
||||||
clazz.getName(), resourcePath));
|
+ "classpath resource [%s] does not exist.", clazz.getName(), resourcePath));
|
||||||
|
}
|
||||||
return EMPTY_STRING_ARRAY;
|
return EMPTY_STRING_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,11 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configClasses.isEmpty()) {
|
if (configClasses.isEmpty()) {
|
||||||
logger.warn(String.format(
|
if (logger.isInfoEnabled()) {
|
||||||
"Test class [%s] does not declare any static, non-private, non-final, inner classes annotated "
|
logger.info(String.format("Cannot generate default configuration classes for test class [%s]: "
|
||||||
+ "with @Configuration that can be used as a default configuration class.", declaringClass));
|
+ "test class does not declare any static, non-private, non-final, inner classes "
|
||||||
|
+ "annotated with @Configuration.", declaringClass));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return configClasses.toArray(new Class<?>[configClasses.size()]);
|
return configClasses.toArray(new Class<?>[configClasses.size()]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue