org.springframework.context

## 接口 ConfigurableApplicationContext

- 所有超级接口:
    ApplicationContext, ApplicationEventPublisher, AutoCloseable, org.springframework.beans.factory.BeanFactory, Closeable, org.springframework.core.env.EnvironmentCapable, org.springframework.beans.factory.HierarchicalBeanFactory, Lifecycle, org.springframework.beans.factory.ListableBeanFactory, MessageSource, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver
  所有已知实现类:
    AbstractApplicationContext, AbstractRefreshableApplicationContext, AbstractRefreshableConfigApplicationContext, AbstractXmlApplicationContext, AnnotationConfigApplicationContext, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, GenericApplicationContext, GenericGroovyApplicationContext, GenericXmlApplicationContext, StaticApplicationContext

      public interface ConfigurableApplicationContext
      extends ApplicationContext, Lifecycle, Closeable

  SPI interface to be implemented by most if not all application contexts. Provides facilities to configure an application context in addition to the application context client methods in the `ApplicationContext` interface.

  Configuration and lifecycle methods are encapsulated here to avoid making them obvious to ApplicationContext client code. The present methods should only be used by startup and shutdown code.

  从以下版本开始:
    03.11.2003
  作者:
    Juergen Hoeller, Chris Beams

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static String` | `CONFIG_LOCATION_DELIMITERS` Any number of these characters are considered delimiters between multiple context config paths in a single String value.
    `static String` | `CONVERSION_SERVICE_BEAN_NAME` Name of the ConversionService bean in the factory.
    `static String` | `ENVIRONMENT_BEAN_NAME` Name of the `Environment` bean in the factory.
    `static String` | `LOAD_TIME_WEAVER_BEAN_NAME` Name of the LoadTimeWeaver bean in the factory.
    `static String` | `SYSTEM_ENVIRONMENT_BEAN_NAME` Name of the System environment bean in the factory.
    `static String` | `SYSTEM_PROPERTIES_BEAN_NAME` Name of the System properties bean in the factory.

    - ### 从接口继承的字段 org.springframework.beans.factory.BeanFactory

      `FACTORY_BEAN_PREFIX`

    - ### 从接口继承的字段 org.springframework.core.io.support.ResourcePatternResolver

      `CLASSPATH_ALL_URL_PREFIX`

    - ### 从接口继承的字段 org.springframework.core.io.ResourceLoader

      `CLASSPATH_URL_PREFIX`

  - ### 方法概要

    所有方法 实例方法 抽象方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `addApplicationListener(ApplicationListener<?> listener)` Add a new ApplicationListener that will be notified on context events such as context refresh and context shutdown.
    `void` | `addBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor)` Add a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated.
    `void` | `addProtocolResolver(org.springframework.core.io.ProtocolResolver resolver)` Register the given protocol resolver with this application context, allowing for additional resource protocols to be handled.
    `void` | `close()` Close this application context, releasing all resources and locks that the implementation might hold.
    `org.springframework.beans.factory.config.ConfigurableListableBeanFactory` | `getBeanFactory()` Return the internal bean factory of this application context.
    `org.springframework.core.env.ConfigurableEnvironment` | `getEnvironment()` Return the `Environment` for this application context in configurable form, allowing for further customization.
    `boolean` | `isActive()` Determine whether this application context is active, that is, whether it has been refreshed at least once and has not been closed yet.
    `void` | `refresh()` Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.
    `void` | `registerShutdownHook()` Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.
    `void` | `setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)` Set the `Environment` for this application context.
    `void` | `setId(String id)` Set the unique id of this application context.
    `void` | `setParent(ApplicationContext parent)` Set the parent of this application context.

    - ### 从接口继承的方法 org.springframework.context.ApplicationContext

      `getApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate`

    - ### 从接口继承的方法 org.springframework.beans.factory.ListableBeanFactory

      `containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation`

    - ### 从接口继承的方法 org.springframework.beans.factory.HierarchicalBeanFactory

      `containsLocalBean, getParentBeanFactory`

    - ### 从接口继承的方法 org.springframework.beans.factory.BeanFactory

      `containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch`

    - ### 从接口继承的方法 org.springframework.context.MessageSource

      `getMessage, getMessage, getMessage`

    - ### 从接口继承的方法 org.springframework.context.ApplicationEventPublisher

      `publishEvent, publishEvent`

    - ### 从接口继承的方法 org.springframework.core.io.support.ResourcePatternResolver

      `getResources`

    - ### 从接口继承的方法 org.springframework.core.io.ResourceLoader

      `getClassLoader, getResource`

    - ### 从接口继承的方法 org.springframework.context.Lifecycle

      `isRunning, start, stop`

- - ### 字段详细资料

    - #### CONFIG_LOCATION_DELIMITERS

          static final String CONFIG_LOCATION_DELIMITERS

      Any number of these characters are considered delimiters between multiple context config paths in a single String value.
      另请参阅:
        `AbstractRefreshableConfigApplicationContext.setConfigLocation(java.lang.String)`, 常量字段值

    - #### CONVERSION_SERVICE_BEAN_NAME

          static final String CONVERSION_SERVICE_BEAN_NAME

      Name of the ConversionService bean in the factory. If none is supplied, default conversion rules apply.
      从以下版本开始:
        3.0
      另请参阅:
        `ConversionService`, 常量字段值

    - #### LOAD_TIME_WEAVER_BEAN_NAME

          static final String LOAD_TIME_WEAVER_BEAN_NAME

      Name of the LoadTimeWeaver bean in the factory. If such a bean is supplied, the context will use a temporary ClassLoader for type matching, in order to allow the LoadTimeWeaver to process all actual bean classes.
      从以下版本开始:
        2.5
      另请参阅:
        `LoadTimeWeaver`, 常量字段值

    - #### ENVIRONMENT_BEAN_NAME

          static final String ENVIRONMENT_BEAN_NAME

      Name of the `Environment` bean in the factory.
      从以下版本开始:
        3.1
      另请参阅:
        常量字段值

    - #### SYSTEM_PROPERTIES_BEAN_NAME

          static final String SYSTEM_PROPERTIES_BEAN_NAME

      Name of the System properties bean in the factory.
      另请参阅:
        `System.getProperties()`, 常量字段值

    - #### SYSTEM_ENVIRONMENT_BEAN_NAME

          static final String SYSTEM_ENVIRONMENT_BEAN_NAME

      Name of the System environment bean in the factory.
      另请参阅:
        `System.getenv()`, 常量字段值

  - ### 方法详细资料

    - #### setId

          void setId(String id)

      Set the unique id of this application context.
      从以下版本开始:
        3.0

    - #### setParent

          void setParent(@Nullable
                         ApplicationContext parent)

      Set the parent of this application context.

      Note that the parent shouldn't be changed: It should only be set outside a constructor if it isn't available when an object of this class is created, for example in case of WebApplicationContext setup.

      参数:
        `parent` - the parent context

    - #### setEnvironment

          void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)

      Set the `Environment` for this application context.
      参数:
        `environment` - the new environment
      从以下版本开始:
        3.1

    - #### getEnvironment

          org.springframework.core.env.ConfigurableEnvironment getEnvironment()

      Return the `Environment` for this application context in configurable form, allowing for further customization.
      指定者:
        `getEnvironment` 在接口中 `org.springframework.core.env.EnvironmentCapable`
      从以下版本开始:
        3.1

    - #### addBeanFactoryPostProcessor

          void addBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor)

      Add a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated. To be invoked during context configuration.
      参数:
        `postProcessor` - the factory processor to register

    - #### addApplicationListener

          void addApplicationListener(ApplicationListener<?> listener)

      Add a new ApplicationListener that will be notified on context events such as context refresh and context shutdown.

      Note that any ApplicationListener registered here will be applied on refresh if the context is not active yet, or on the fly with the current event multicaster in case of a context that is already active.

      参数:
        `listener` - the ApplicationListener to register
      另请参阅:
        `ContextRefreshedEvent`, `ContextClosedEvent`

    - #### addProtocolResolver

          void addProtocolResolver(org.springframework.core.io.ProtocolResolver resolver)

      Register the given protocol resolver with this application context, allowing for additional resource protocols to be handled.

      Any such resolver will be invoked ahead of this context's standard resolution rules. It may therefore also override any default rules.

      从以下版本开始:
        4.3

    - #### refresh

          void refresh()
                throws org.springframework.beans.BeansException,
                       IllegalStateException

      Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.

      As this is a startup method, it should destroy already created singletons if it fails, to avoid dangling resources. In other words, after invocation of that method, either all or no singletons at all should be instantiated.

      抛出:
        `org.springframework.beans.BeansException` - if the bean factory could not be initialized
        `IllegalStateException` - if already initialized and multiple refresh attempts are not supported

    - #### registerShutdownHook

          void registerShutdownHook()

      Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.

      This method can be called multiple times. Only one shutdown hook (at max) will be registered for each context instance.

      另请参阅:
        `Runtime.addShutdownHook(java.lang.Thread)`, `close()`

    - #### close

          void close()

      Close this application context, releasing all resources and locks that the implementation might hold. This includes destroying all cached singleton beans.

      Note: Does not invoke `close` on a parent context; parent contexts have their own, independent lifecycle.

      This method can be called multiple times without side effects: Subsequent `close` calls on an already closed context will be ignored.

      指定者:
        `close` 在接口中 `AutoCloseable`
      指定者:
        `close` 在接口中 `Closeable`

    - #### isActive

          boolean isActive()

      Determine whether this application context is active, that is, whether it has been refreshed at least once and has not been closed yet.
      返回:
        whether the context is still active
      另请参阅:
        `refresh()`, `close()`, `getBeanFactory()`

    - #### getBeanFactory

          org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()
                                                                                           throws IllegalStateException

      Return the internal bean factory of this application context. Can be used to access specific functionality of the underlying factory.

      Note: Do not use this to post-process the bean factory; singletons will already have been instantiated before. Use a BeanFactoryPostProcessor to intercept the BeanFactory setup process before beans get touched.

      Generally, this internal factory will only be accessible while the context is active, that is, in-between `refresh()` and `close()`. The `isActive()` flag can be used to check whether the context is in an appropriate state.

      返回:
        the underlying bean factory
      抛出:
        `IllegalStateException` - if the context does not hold an internal bean factory (usually if `refresh()` hasn't been called yet or if `close()` has already been called)
      另请参阅:
        `isActive()`, `refresh()`, `close()`, `addBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor)`