LiveBeansView (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.context.support

## Class LiveBeansView

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

- All Implemented Interfaces:
    Aware, ApplicationContextAware, LiveBeansViewMBean
  Direct Known Subclasses:
    ServletContextLiveBeansView

      public class LiveBeansView
      extends Object
      implements LiveBeansViewMBean, ApplicationContextAware

  Adapter for live beans view exposure, building a snapshot of current beans and their dependencies from either a local `ApplicationContext` (with a local `LiveBeansView` bean definition) or all registered ApplicationContexts (driven by the "spring.liveBeansView.mbeanDomain" environment property).

  Note: This feature is still in beta and primarily designed for use with Spring Tool Suite 3.1.

  Since:
    3.2
  Author:
    Juergen Hoeller
  See Also:
    `getSnapshotAsJson()`, `LiveBeansViewServlet`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `MBEAN_APPLICATION_KEY`
    `static String` | `MBEAN_DOMAIN_PROPERTY_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LiveBeansView()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Set<ConfigurableApplicationContext>` | `findApplicationContexts()` Find all applicable ApplicationContexts for the current application.
    `protected String` | `generateJson(Set<ConfigurableApplicationContext> contexts)` Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
    `String` | `getSnapshotAsJson()` Generate a JSON snapshot of current beans and their dependencies, finding all active ApplicationContexts through `findApplicationContexts()`, then delegating to `generateJson(java.util.Set)`.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### MBEAN_DOMAIN_PROPERTY_NAME

          public static final String MBEAN_DOMAIN_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### MBEAN_APPLICATION_KEY

          public static final String MBEAN_APPLICATION_KEY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LiveBeansView

          public LiveBeansView()

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)

      Description copied from interface: `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.

      Specified by:
        `setApplicationContext` in interface `ApplicationContextAware`
      Parameters:
        `applicationContext` - the ApplicationContext object to be used by this object
      See Also:
        `BeanInitializationException`

    - #### getSnapshotAsJson

          public String getSnapshotAsJson()

      Generate a JSON snapshot of current beans and their dependencies, finding all active ApplicationContexts through `findApplicationContexts()`, then delegating to `generateJson(java.util.Set)`.
      Specified by:
        `getSnapshotAsJson` in interface `LiveBeansViewMBean`

    - #### generateJson

          protected String generateJson(Set<ConfigurableApplicationContext> contexts)

      Actually generate a JSON snapshot of the beans in the given ApplicationContexts.

      This implementation doesn't use any JSON parsing libraries in order to avoid third-party library dependencies. It produces an array of context description objects, each containing a context and parent attribute as well as a beans attribute with nested bean description objects. Each bean object contains a bean, scope, type and resource attribute, as well as a dependencies attribute with a nested array of bean names that the present bean depends on.

      Parameters:
        `contexts` - the set of ApplicationContexts
      Returns:
        the JSON document

    - #### findApplicationContexts

          protected Set<ConfigurableApplicationContext> findApplicationContexts()

      Find all applicable ApplicationContexts for the current application.

      Called if no specific ApplicationContext has been set for this LiveBeansView.

      Returns:
        the set of ApplicationContexts