注释类型 ContextConfiguration

      • inheritLocations

        boolean inheritLocations
        Whether or not resource locations or annotated classes from test superclasses should be inherited.

        The default value is true. This means that an annotated class will inherit the resource locations or annotated 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. Thus, subclasses have the option of extending the list of resource locations or annotated classes.

        If inheritLocations is set to false, the resource locations or annotated classes for the annotated class will shadow and effectively replace any resource locations or annotated classes defined by superclasses.

        In the following example that uses path-based resource locations, the ApplicationContext for ExtendedTest will be loaded from "base-context.xml"and"extended-context.xml", in that order. Beans defined in "extended-context.xml" may therefore override those defined in "base-context.xml".

         @ContextConfiguration("base-context.xml")
         public class BaseTest {
             // ...
         }
        
         @ContextConfiguration("extended-context.xml")
         public class ExtendedTest extends BaseTest {
             // ...
         }
         

        Similarly, in the following example that uses annotated classes, the ApplicationContext for ExtendedTest will be loaded from the BaseConfigandExtendedConfig configuration classes, in that order. Beans defined in ExtendedConfig may therefore override those defined in BaseConfig.

         @ContextConfiguration(classes=BaseConfig.class)
         public class BaseTest {
             // ...
         }
        
         @ContextConfiguration(classes=ExtendedConfig.class)
         public class ExtendedTest extends BaseTest {
             // ...
         }
         
        从以下版本开始:
        2.5
        默认值:
        true
      • inheritInitializers

        boolean inheritInitializers
        Whether or not context initializers from test superclasses should be inherited.

        The default value is true. This means that an annotated class will inherit 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 extending the set of initializers.

        If inheritInitializers is set to false, the initializers for the annotated class will shadow and effectively replace any initializers defined by superclasses.

        In the following example, the ApplicationContext for ExtendedTest will be initialized using BaseInitializerandExtendedInitializer. Note, however, that the order in which the initializers are invoked depends on whether they implement Ordered or are annotated with @Order.

         @ContextConfiguration(initializers = BaseInitializer.class)
         public class BaseTest {
             // ...
         }
        
         @ContextConfiguration(initializers = ExtendedInitializer.class)
         public class ExtendedTest extends BaseTest {
             // ...
         }
         
        从以下版本开始:
        3.2
        默认值:
        true
      • name

        String name
        The name of the context hierarchy level represented by this configuration.

        If not specified the name will be inferred based on the numerical level within all declared contexts within the hierarchy.

        This attribute is only applicable when used within a test class hierarchy that is configured using @ContextHierarchy, in which case the name can be used for merging or overriding this configuration with configuration of the same name in hierarchy levels defined in superclasses. See the Javadoc for @ContextHierarchy for details.

        从以下版本开始:
        3.2.2
        默认值:
        ""