org.springframework.context.support

## 类 ApplicationObjectSupport

- java.lang.Object
- - org.springframework.context.support.ApplicationObjectSupport

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, ApplicationContextAware

      public abstract class ApplicationObjectSupport
      extends Object
      implements ApplicationContextAware

  Convenient superclass for application objects that want to be aware of the application context, e.g. for custom lookup of collaborating beans or for context-specific resource access. It saves the application context reference and provides an initialization callback method. Furthermore, it offers numerous convenience methods for message lookup.

  There is no requirement to subclass this class: It just makes things a little easier if you need access to the context, e.g. for access to file resources or to the message source. Note that many application objects do not need to be aware of the application context at all, as they can receive collaborating beans via bean references.

  Many framework classes are derived from this class, particularly within the web support.

  作者:
    Rod Johnson, Juergen Hoeller
  另请参阅:
    `org.springframework.web.context.support.WebApplicationObjectSupport`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `protected Log` | `logger` Logger that is available to subclasses

  - ### 构造器概要

    构造器
    构造器和说明
    `ApplicationObjectSupport()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `ApplicationContext` | `getApplicationContext()` Return the ApplicationContext that this object is associated with.
    `protected MessageSourceAccessor` | `getMessageSourceAccessor()` Return a MessageSourceAccessor for the application context used by this object, for easy message access.
    `protected void` | `initApplicationContext()` Subclasses can override this for custom initialization behavior.
    `protected void` | `initApplicationContext(ApplicationContext context)` Subclasses can override this for custom initialization behavior.
    `protected boolean` | `isContextRequired()` Determine whether this application object needs to run in an ApplicationContext.
    `protected ApplicationContext` | `obtainApplicationContext()` Obtain the ApplicationContext for actual use.
    `protected Class<?>` | `requiredContextClass()` Determine the context class that any context passed to `setApplicationContext` must be an instance of.
    `void` | `setApplicationContext(ApplicationContext context)` Set the ApplicationContext that this object runs in.

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 字段详细资料

    - #### logger

          protected final Log logger

      Logger that is available to subclasses

  - ### 构造器详细资料

    - #### ApplicationObjectSupport

          public ApplicationObjectSupport()

  - ### 方法详细资料

    - #### setApplicationContext

          public final void setApplicationContext(@Nullable
                                                  ApplicationContext context)
                                           throws org.springframework.beans.BeansException

      从接口复制的说明: `ApplicationContextAware`
      Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

      Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      指定者:
        `setApplicationContext` 在接口中 `ApplicationContextAware`
      参数:
        `context` - the ApplicationContext object to be used by this object
      抛出:
        `ApplicationContextException` - in case of context initialization errors
        `org.springframework.beans.BeansException` - if thrown by application context methods
      另请参阅:
        `BeanInitializationException`

    - #### isContextRequired

          protected boolean isContextRequired()

      Determine whether this application object needs to run in an ApplicationContext.

      Default is "false". Can be overridden to enforce running in a context (i.e. to throw IllegalStateException on accessors if outside a context).

      另请参阅:
        `getApplicationContext()`, `getMessageSourceAccessor()`

    - #### requiredContextClass

          protected Class<?> requiredContextClass()

      Determine the context class that any context passed to `setApplicationContext` must be an instance of. Can be overridden in subclasses.
      另请参阅:
        `setApplicationContext(org.springframework.context.ApplicationContext)`

    - #### initApplicationContext

          protected void initApplicationContext(ApplicationContext context)
                                         throws org.springframework.beans.BeansException

      Subclasses can override this for custom initialization behavior. Gets called by `setApplicationContext` after setting the context instance.

      Note: Does not get called on reinitialization of the context but rather just on first initialization of this object's context reference.

      The default implementation calls the overloaded `initApplicationContext()` method without ApplicationContext reference.

      参数:
        `context` - the containing ApplicationContext
      抛出:
        `ApplicationContextException` - in case of initialization errors
        `org.springframework.beans.BeansException` - if thrown by ApplicationContext methods
      另请参阅:
        `setApplicationContext(org.springframework.context.ApplicationContext)`

    - #### initApplicationContext

          protected void initApplicationContext()
                                         throws org.springframework.beans.BeansException

      Subclasses can override this for custom initialization behavior.

      The default implementation is empty. Called by `initApplicationContext(org.springframework.context.ApplicationContext)`.

      抛出:
        `ApplicationContextException` - in case of initialization errors
        `org.springframework.beans.BeansException` - if thrown by ApplicationContext methods
      另请参阅:
        `setApplicationContext(org.springframework.context.ApplicationContext)`

    - #### getApplicationContext

          @Nullable
          public final ApplicationContext getApplicationContext()
                                                                    throws IllegalStateException

      Return the ApplicationContext that this object is associated with.
      抛出:
        `IllegalStateException` - if not running in an ApplicationContext

    - #### obtainApplicationContext

          protected final ApplicationContext obtainApplicationContext()

      Obtain the ApplicationContext for actual use.
      返回:
        the ApplicationContext (never `null`)
      抛出:
        `IllegalStateException` - in case of no ApplicationContext set
      从以下版本开始:
        5.0

    - #### getMessageSourceAccessor

          @Nullable
          protected final MessageSourceAccessor getMessageSourceAccessor()
                                                                             throws IllegalStateException

      Return a MessageSourceAccessor for the application context used by this object, for easy message access.
      抛出:
        `IllegalStateException` - if not running in an ApplicationContext