接口 ApplicationContextInitializer

函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface public interface ApplicationContextInitializer
Callback interface for initializing a ConfigurableApplicationContext prior to being refreshed.

Typically used within web applications that require some programmatic initialization of the application context. For example, registering property sources or activating profiles against the context's environment.

ApplicationContextInitializer processors are encouraged to detect whether Ordered interface has been implemented or if the @Order annotation is present and to sort instances accordingly if so prior to invocation.

从以下版本开始:
4.0
作者:
Chris Beams, TODAY 2021/11/5 10:29
  • 方法详细资料

    • initialize

      void initialize(ConfigurableApplicationContext context)
      Initialize the given application context.

      before using applicationContext you must test if context is you want. like this:

        if (applicationContext instanceof GenericApplicationContext generic) {
      
        }
       
      参数:
      context - the application to configure (never null)