Merge branch '5.1.x'
This commit is contained in:
@@ -41,15 +41,15 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <em>and</em> class-based resources simultaneously. Consequently
|
||||
* {@code @ContextConfiguration} can be used to declare either path-based resource
|
||||
* locations (via the {@link #locations} or {@link #value} attribute) <em>or</em>
|
||||
* annotated classes (via the {@link #classes} attribute). Note, however, that most
|
||||
* component classes (via the {@link #classes} attribute). Note, however, that most
|
||||
* implementations of {@link SmartContextLoader} only support a single resource type. As
|
||||
* of Spring 4.1, path-based resource locations may be either XML configuration files or
|
||||
* Groovy scripts (if Groovy is on the classpath). Of course, third-party frameworks may
|
||||
* choose to support additional types of path-based resources.
|
||||
*
|
||||
* <h3>Annotated Classes</h3>
|
||||
* <h3>Component Classes</h3>
|
||||
*
|
||||
* <p>The term <em>annotated class</em> can refer to any of the following.
|
||||
* <p>The term <em>component class</em> can refer to any of the following.
|
||||
*
|
||||
* <ul>
|
||||
* <li>A class annotated with {@link org.springframework.context.annotation.Configuration @Configuration}</li>
|
||||
@@ -58,15 +58,22 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* {@link org.springframework.stereotype.Service @Service},
|
||||
* {@link org.springframework.stereotype.Repository @Repository}, etc.)</li>
|
||||
* <li>A JSR-330 compliant class that is annotated with {@code javax.inject} annotations</li>
|
||||
* <li>Any other class that contains {@link org.springframework.context.annotation.Bean @Bean}-methods</li>
|
||||
* <li>Any class that contains {@link org.springframework.context.annotation.Bean @Bean}-methods</li>
|
||||
* <li>Any other class that is intended to be registered as a Spring component (i.e., a Spring bean
|
||||
* in the {@code ApplicationContext}), potentially taking advantage of automatic autowiring of a
|
||||
* single constructor without the use of Spring annotations</li>
|
||||
* </ul>
|
||||
*
|
||||
* A bean will be registered in the {@code ApplicationContext} for each component
|
||||
* class, and such beans can therefore be injected into other beans or into the
|
||||
* instance of the test class.
|
||||
*
|
||||
* <p>Consult the Javadoc for {@link org.springframework.context.annotation.Configuration @Configuration}
|
||||
* and {@link org.springframework.context.annotation.Bean @Bean} for further
|
||||
* information regarding the configuration and semantics of <em>annotated classes</em>.
|
||||
* information regarding the configuration and semantics of <em>component classes</em>.
|
||||
*
|
||||
* <p>As of Spring Framework 4.0, this annotation may be used as a <em>meta-annotation</em>
|
||||
* to create custom <em>composed annotations</em>.
|
||||
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
|
||||
* <em>composed annotations</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
@@ -124,13 +131,13 @@ public @interface ContextConfiguration {
|
||||
String[] locations() default {};
|
||||
|
||||
/**
|
||||
* The <em>annotated classes</em> to use for loading an
|
||||
* The <em>component classes</em> to use for loading an
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
||||
* <p>Check out the javadoc for
|
||||
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#detectDefaultConfigurationClasses
|
||||
* AnnotationConfigContextLoader.detectDefaultConfigurationClasses()} for details
|
||||
* on how default configuration classes will be detected if no
|
||||
* <em>annotated classes</em> are specified. See the documentation for
|
||||
* <em>component classes</em> are specified. See the documentation for
|
||||
* {@link #loader} for further details regarding default loaders.
|
||||
* @since 3.1
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
@@ -158,19 +165,20 @@ public @interface ContextConfiguration {
|
||||
Class<? extends ApplicationContextInitializer<?>>[] initializers() default {};
|
||||
|
||||
/**
|
||||
* Whether or not {@link #locations resource locations} or <em>annotated
|
||||
* classes</em> from test superclasses should be <em>inherited</em>.
|
||||
* <p>The default value is {@code true}. This means that an annotated
|
||||
* class will <em>inherit</em> the resource locations or annotated classes
|
||||
* Whether or not {@linkplain #locations resource locations} or
|
||||
* {@linkplain #classes <em>component classes</em>} from test superclasses
|
||||
* should be <em>inherited</em>.
|
||||
* <p>The default value is {@code true}. This means that an annotated test
|
||||
* class will <em>inherit</em> the resource locations or component classes
|
||||
* defined by test superclasses. Specifically, the resource locations or
|
||||
* annotated classes for a given test class will be appended to the list of
|
||||
* resource locations or annotated classes defined by test superclasses.
|
||||
* component classes for a given test class will be appended to the list of
|
||||
* resource locations or component classes defined by test superclasses.
|
||||
* Thus, subclasses have the option of <em>extending</em> the list of resource
|
||||
* locations or annotated classes.
|
||||
* locations or component classes.
|
||||
* <p>If {@code inheritLocations} is set to {@code false}, the
|
||||
* resource locations or annotated classes for the annotated class
|
||||
* resource locations or component classes for the annotated test class
|
||||
* will <em>shadow</em> and effectively replace any resource locations
|
||||
* or annotated classes defined by superclasses.
|
||||
* or component classes defined by superclasses.
|
||||
* <p>In the following example that uses path-based resource locations, the
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
* for {@code ExtendedTest} will be loaded from
|
||||
@@ -189,8 +197,7 @@ public @interface ContextConfiguration {
|
||||
* // ...
|
||||
* }
|
||||
* </pre>
|
||||
* <p>Similarly, in the following example that uses annotated
|
||||
* classes, the
|
||||
* <p>Similarly, in the following example that uses component classes, the
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
* for {@code ExtendedTest} will be loaded from the
|
||||
* {@code BaseConfig} <strong>and</strong> {@code ExtendedConfig}
|
||||
@@ -215,15 +222,15 @@ public @interface ContextConfiguration {
|
||||
/**
|
||||
* Whether or not {@linkplain #initializers context initializers} from test
|
||||
* superclasses should be <em>inherited</em>.
|
||||
* <p>The default value is {@code true}. This means that an annotated
|
||||
* <p>The default value is {@code true}. This means that an annotated test
|
||||
* class will <em>inherit</em> the application context initializers defined
|
||||
* by test superclasses. Specifically, the initializers for a given test
|
||||
* class will be added to the set of initializers defined by test
|
||||
* superclasses. Thus, subclasses have the option of <em>extending</em> the
|
||||
* set of initializers.
|
||||
* <p>If {@code inheritInitializers} is set to {@code false}, the
|
||||
* initializers for the annotated class will <em>shadow</em> and effectively
|
||||
* replace any initializers defined by superclasses.
|
||||
* <p>If {@code inheritInitializers} is set to {@code false}, the initializers
|
||||
* for the annotated test class will <em>shadow</em> and effectively replace
|
||||
* any initializers defined by superclasses.
|
||||
* <p>In the following example, the
|
||||
* {@link org.springframework.context.ApplicationContext ApplicationContext}
|
||||
* for {@code ExtendedTest} will be initialized using
|
||||
@@ -252,9 +259,9 @@ public @interface ContextConfiguration {
|
||||
* for loading an {@link org.springframework.context.ApplicationContext
|
||||
* ApplicationContext}.
|
||||
* <p>If not specified, the loader will be inherited from the first superclass
|
||||
* that is annotated with {@code @ContextConfiguration} and specifies an
|
||||
* explicit loader. If no class in the hierarchy specifies an explicit
|
||||
* loader, a default loader will be used instead.
|
||||
* that is annotated or meta-annotated with {@code @ContextConfiguration} and
|
||||
* specifies an explicit loader. If no class in the hierarchy specifies an
|
||||
* explicit loader, a default loader will be used instead.
|
||||
* <p>The default concrete implementation chosen at runtime will be either
|
||||
* {@link org.springframework.test.context.support.DelegatingSmartContextLoader
|
||||
* DelegatingSmartContextLoader} or
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,13 +28,13 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Concrete implementation of {@link AbstractGenericContextLoader} that loads
|
||||
* bean definitions from annotated classes.
|
||||
* bean definitions from component classes.
|
||||
*
|
||||
* <p>See the Javadoc for
|
||||
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration}
|
||||
* for a definition of <em>annotated class</em>.
|
||||
* for a definition of <em>component class</em>.
|
||||
*
|
||||
* <p>Note: {@code AnnotationConfigContextLoader} supports <em>annotated classes</em>
|
||||
* <p>Note: {@code AnnotationConfigContextLoader} supports <em>component classes</em>
|
||||
* rather than the String-based resource locations defined by the legacy
|
||||
* {@link org.springframework.test.context.ContextLoader ContextLoader} API. Thus,
|
||||
* although {@code AnnotationConfigContextLoader} extends
|
||||
@@ -61,8 +61,8 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
||||
// SmartContextLoader
|
||||
|
||||
/**
|
||||
* Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}.
|
||||
* <p>If the <em>annotated classes</em> are {@code null} or empty and
|
||||
* Process <em>component classes</em> in the supplied {@link ContextConfigurationAttributes}.
|
||||
* <p>If the <em>component classes</em> are {@code null} or empty and
|
||||
* {@link #isGenerateDefaultLocations()} returns {@code true}, this
|
||||
* {@code SmartContextLoader} will attempt to {@link
|
||||
* #detectDefaultConfigurationClasses detect default configuration classes}.
|
||||
@@ -167,23 +167,23 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
||||
/**
|
||||
* Register classes in the supplied {@link GenericApplicationContext context}
|
||||
* from the classes in the supplied {@link MergedContextConfiguration}.
|
||||
* <p>Each class must represent an <em>annotated class</em>. An
|
||||
* <p>Each class must represent a <em>component class</em>. An
|
||||
* {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
|
||||
* bean definitions.
|
||||
* <p>Note that this method does not call {@link #createBeanDefinitionReader}
|
||||
* since {@code AnnotatedBeanDefinitionReader} is not an instance of
|
||||
* {@link BeanDefinitionReader}.
|
||||
* @param context the context in which the annotated classes should be registered
|
||||
* @param context the context in which the component classes should be registered
|
||||
* @param mergedConfig the merged configuration from which the classes should be retrieved
|
||||
* @see AbstractGenericContextLoader#loadBeanDefinitions
|
||||
*/
|
||||
@Override
|
||||
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
Class<?>[] annotatedClasses = mergedConfig.getClasses();
|
||||
Class<?>[] componentClasses = mergedConfig.getClasses();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
|
||||
logger.debug("Registering component classes: " + ObjectUtils.nullSafeToString(componentClasses));
|
||||
}
|
||||
new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
|
||||
new AnnotatedBeanDefinitionReader(context).register(componentClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for {@link SmartContextLoader SmartContextLoaders} that deal
|
||||
* with annotated classes (e.g., {@link Configuration @Configuration} classes).
|
||||
* with component classes (e.g., {@link Configuration @Configuration} classes).
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
|
||||
Reference in New Issue
Block a user