接口 SmartContextLoader

所有超级接口:
ContextLoader
所有已知子接口:
AotContextLoader
所有已知实现类:
AbstractContextLoader, AbstractDelegatingSmartContextLoader, AbstractGenericContextLoader, AbstractGenericWebContextLoader, AnnotationConfigContextLoader, AnnotationConfigWebContextLoader, DelegatingSmartContextLoader, GenericPropertiesContextLoader, GenericXmlContextLoader, GenericXmlWebContextLoader, InfraApplicationContextLoader, WebDelegatingSmartContextLoader

public interface SmartContextLoader extends ContextLoader
Strategy interface for loading an application context for an integration test managed by the TestContext Framework.

The SmartContextLoader SPI supersedes the ContextLoader SPI introduced a SmartContextLoader can choose to process either resource locations or annotated classes. Furthermore, a SmartContextLoader can set active bean definition profiles in the context that it loads (see MergedContextConfiguration.getActiveProfiles() and loadContext(MergedContextConfiguration)).

See the Javadoc for @ContextConfiguration for a definition of annotated class.

Clients of a SmartContextLoader should call processContextConfiguration() prior to calling loadContext(). This gives a SmartContextLoader the opportunity to provide custom support for modifying resource locations or detecting default resource locations or default configuration classes. The results of processContextConfiguration() should be merged for all classes in the hierarchy of the root test class and then supplied to loadContext().

Even though SmartContextLoader extends ContextLoader, clients should favor SmartContextLoader-specific methods over those defined in ContextLoader, particularly because a SmartContextLoader may choose not to support methods defined in the ContextLoader SPI.

Concrete implementations must provide a public no-args constructor.

provides the following out-of-the-box implementations:

从以下版本开始:
4.0
作者:
Sam Brannen, Harry Yang
另请参阅:
  • 方法详细资料

    • processContextConfiguration

      void processContextConfiguration(ContextConfigurationAttributes configAttributes)
      Process the ContextConfigurationAttributes for a given test class.

      Concrete implementations may choose to modify the locations or classes in the supplied ContextConfigurationAttributes, generate default configuration locations, or detect default configuration classes if the supplied values are null or empty.

      Note: a SmartContextLoader must preemptively verify that a generated or detected default actually exists before setting the corresponding locations or classes property in the supplied ContextConfigurationAttributes. Consequently, leaving the locations or classes property empty signals that this SmartContextLoader was not able to generate or detect defaults.

      参数:
      configAttributes - the context configuration attributes to process
    • loadContext

      cn.taketoday.context.ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception
      Load a new ApplicationContext based on the supplied MergedContextConfiguration, configure the context, and return the context in a fully refreshed state.

      Concrete implementations should register annotation configuration processors with bean factories of application contexts loaded by this SmartContextLoader. Beans will therefore automatically be candidates for annotation-based dependency injection using @Autowired, @Resource, and @Inject. In addition, concrete implementations should perform the following actions.

      any exception thrown while attempting to load an ApplicationContext should be wrapped in a ContextLoadException. Concrete implementations should therefore contain a try-catch block similar to the following.

       ApplicationContext context = // create context
       try {
           // configure and refresh context
       }
       catch (Exception ex) {
           throw new ContextLoadException(context, ex);
       }
       
      参数:
      mergedConfig - the merged context configuration to use to load the application context
      返回:
      a new application context
      抛出:
      ContextLoadException - if context loading failed
      Exception
      另请参阅:
    • processLocations

      default String[] processLocations(Class<?> clazz, @Nullable String... locations)
      SmartContextLoader does not support deprecated ContextLoader methods. Call processContextConfiguration(ContextConfigurationAttributes) instead.
      指定者:
      processLocations 在接口中 ContextLoader
      参数:
      clazz - the class with which the locations are associated: used to determine how to process the supplied locations
      locations - the unmodified locations to use for loading the application context (can be null or empty)
      返回:
      an array of application context resource locations
      抛出:
      UnsupportedOperationException - in this implementation
    • loadContext

      default cn.taketoday.context.ApplicationContext loadContext(String... locations) throws Exception
      SmartContextLoader does not support deprecated ContextLoader methods.

      Call loadContext(MergedContextConfiguration) instead.

      指定者:
      loadContext 在接口中 ContextLoader
      参数:
      locations - the resource locations to use to load the application context
      返回:
      a new application context
      抛出:
      UnsupportedOperationException - in this implementation
      Exception - if context loading failed