org.springframework.jmx.export

## 类 MBeanExporter

- java.lang.Object
- - org.springframework.jmx.support.MBeanRegistrationSupport
  - - org.springframework.jmx.export.MBeanExporter

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, MBeanExportOperations
  直接已知子类:
    AnnotationMBeanExporter

      public class MBeanExporter
      extends MBeanRegistrationSupport
      implements MBeanExportOperations, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.DisposableBean

  JMX exporter that allows for exposing any Spring-managed bean to a JMX `MBeanServer`, without the need to define any JMX-specific information in the bean classes.

  If a bean implements one of the JMX management interfaces, MBeanExporter can simply register the MBean with the server through its autodetection process.

  If a bean does not implement one of the JMX management interfaces, MBeanExporter will create the management information using the supplied `MBeanInfoAssembler`.

  A list of `MBeanExporterListeners` can be registered via the `listeners` property, allowing application code to be notified of MBean registration and unregistration events.

  This exporter is compatible with MBeans as well as MXBeans.

  从以下版本开始:
    1.2
  作者:
    Rob Harrop, Juergen Hoeller, Rick Evans, Mark Fisher, Stephane Nicoll
  另请参阅:
    `setBeans(java.util.Map<java.lang.String, java.lang.Object>)`, `setAutodetect(boolean)`, `setAssembler(org.springframework.jmx.export.assembler.MBeanInfoAssembler)`, `setListeners(org.springframework.jmx.export.MBeanExporterListener...)`, `MBeanInfoAssembler`, `MBeanExporterListener`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static int` | `AUTODETECT_ALL` Autodetection mode indicating that all autodetection mechanisms should be used.
    `static int` | `AUTODETECT_ASSEMBLER` Autodetection mode indicating that only the `MBeanInfoAssembler` should be able to autodetect beans.
    `static int` | `AUTODETECT_MBEAN` Autodetection mode indicating that only valid MBeans should be autodetected.
    `static int` | `AUTODETECT_NONE` Autodetection mode indicating that no autodetection should be used.

    - ### 从类继承的字段 org.springframework.jmx.support.MBeanRegistrationSupport

      `logger, server`

  - ### 构造器概要

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

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected DynamicMBean` | `adaptMBeanIfPossible(Object bean)` Build an adapted MBean for the given bean instance, if possible.
    `void` | `addExcludedBean(String excludedBean)` Add the name of bean that should be excluded from autodetection.
    `void` | `afterPropertiesSet()`
    `void` | `afterSingletonsInstantiated()` Kick off bean registration automatically after the regular singleton instantiation phase.
    `protected ModelMBean` | `createAndConfigureMBean(Object managedResource, String beanKey)` Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.
    `protected ModelMBean` | `createModelMBean()` Create an instance of a class that implements `ModelMBean`.
    `void` | `destroy()` Unregisters all beans that this exported has exposed via JMX when the enclosing `ApplicationContext` is destroyed.
    `protected ObjectName` | `getObjectName(Object bean, String beanKey)` Retrieve the `ObjectName` for a bean.
    `protected boolean` | `isBeanDefinitionLazyInit(org.springframework.beans.factory.ListableBeanFactory beanFactory, String beanName)` Return whether the specified bean definition should be considered as lazy-init.
    `protected boolean` | `isMBean(Class<?> beanClass)` Determine whether the given bean class qualifies as an MBean as-is.
    `protected void` | `onRegister(ObjectName objectName)` Called when an MBean is registered.
    `protected void` | `onUnregister(ObjectName objectName)` Called when an MBean is unregistered.
    `protected ObjectName` | `registerBeanNameOrInstance(Object mapValue, String beanKey)` Register an individual bean with the `MBeanServer`.
    `protected void` | `registerBeans()` Register the defined beans with the `MBeanServer`.
    `ObjectName` | `registerManagedResource(Object managedResource)` Register the supplied resource with JMX.
    `void` | `registerManagedResource(Object managedResource, ObjectName objectName)` Register the supplied resource with JMX.
    `void` | `setAllowEagerInit(boolean allowEagerInit)` Specify whether to allow eager initialization of candidate beans when autodetecting MBeans in the Spring application context.
    `void` | `setAssembler(MBeanInfoAssembler assembler)` Set the implementation of the `MBeanInfoAssembler` interface to use for this exporter.
    `void` | `setAutodetect(boolean autodetect)` Set whether to autodetect MBeans in the bean factory that this exporter runs in.
    `void` | `setAutodetectMode(int autodetectMode)` Set the autodetection mode to use.
    `void` | `setAutodetectModeName(String constantName)` Set the autodetection mode to use by name.
    `void` | `setBeanClassLoader(ClassLoader classLoader)`
    `void` | `setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)` This callback is only required for resolution of bean names in the `"beans"` `Map` and for autodetection of MBeans (in the latter case, a `ListableBeanFactory` is required).
    `void` | `setBeans(Map<String,Object> beans)` Supply a `Map` of beans to be registered with the JMX `MBeanServer`.
    `void` | `setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)` Indicates whether Spring should ensure that `ObjectNames` generated by the configured `ObjectNamingStrategy` for runtime-registered MBeans (`registerManagedResource(java.lang.Object)`) should get modified: to ensure uniqueness for every instance of a managed `Class`.
    `void` | `setExcludedBeans(String... excludedBeans)` Set the list of names for beans that should be excluded from autodetection.
    `void` | `setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader)` Indicates whether or not the managed resource should be exposed on the `thread context ClassLoader` before allowing any invocations on the MBean to occur.
    `void` | `setListeners(MBeanExporterListener... listeners)` Set the `MBeanExporterListener`s that should be notified of MBean registration and unregistration events.
    `void` | `setNamingStrategy(ObjectNamingStrategy namingStrategy)` Set the implementation of the `ObjectNamingStrategy` interface to use for this exporter.
    `void` | `setNotificationListenerMappings(Map<?,? extends NotificationListener> listeners)` Set the `NotificationListeners` to register with the `MBeanServer`.
    `void` | `setNotificationListeners(NotificationListenerBean... notificationListeners)` Set the `NotificationListenerBeans` containing the `NotificationListeners` that will be registered with the `MBeanServer`.
    `void` | `unregisterManagedResource(ObjectName objectName)` Remove the specified MBean from the underlying MBeanServer registry.

    - ### 从类继承的方法 org.springframework.jmx.support.MBeanRegistrationSupport

      `doRegister, doUnregister, getRegisteredObjectNames, getServer, onRegister, setRegistrationPolicy, setServer, unregisterBeans`

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

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

- - ### 字段详细资料

    - #### AUTODETECT_NONE

          public static final int AUTODETECT_NONE

      Autodetection mode indicating that no autodetection should be used.
      另请参阅:
        常量字段值

    - #### AUTODETECT_MBEAN

          public static final int AUTODETECT_MBEAN

      Autodetection mode indicating that only valid MBeans should be autodetected.
      另请参阅:
        常量字段值

    - #### AUTODETECT_ASSEMBLER

          public static final int AUTODETECT_ASSEMBLER

      Autodetection mode indicating that only the `MBeanInfoAssembler` should be able to autodetect beans.
      另请参阅:
        常量字段值

    - #### AUTODETECT_ALL

          public static final int AUTODETECT_ALL

      Autodetection mode indicating that all autodetection mechanisms should be used.
      另请参阅:
        常量字段值

  - ### 构造器详细资料

    - #### MBeanExporter

          public MBeanExporter()

  - ### 方法详细资料

    - #### setBeans

          public void setBeans(Map<String,Object> beans)

      Supply a `Map` of beans to be registered with the JMX `MBeanServer`.

      The String keys are the basis for the creation of JMX object names. By default, a JMX `ObjectName` will be created straight from the given key. This can be customized through specifying a custom `NamingStrategy`.

      Both bean instances and bean names are allowed as values. Bean instances are typically linked in through bean references. Bean names will be resolved as beans in the current factory, respecting lazy-init markers (that is, not triggering initialization of such beans).

      参数:
        `beans` - a Map with JMX names as keys and bean instances or bean names as values
      另请参阅:
        `setNamingStrategy(org.springframework.jmx.export.naming.ObjectNamingStrategy)`, `KeyNamingStrategy`, `ObjectName.ObjectName(String)`

    - #### setAutodetect

          public void setAutodetect(boolean autodetect)

      Set whether to autodetect MBeans in the bean factory that this exporter runs in. Will also ask an `AutodetectCapableMBeanInfoAssembler` if available.

      This feature is turned off by default. Explicitly specify `true` here to enable autodetection.

      另请参阅:
        `setAssembler(org.springframework.jmx.export.assembler.MBeanInfoAssembler)`, `AutodetectCapableMBeanInfoAssembler`, `isMBean(java.lang.Class<?>)`

    - #### setAutodetectMode

          public void setAutodetectMode(int autodetectMode)

      Set the autodetection mode to use.
      抛出:
        `IllegalArgumentException` - if the supplied value is not one of the `AUTODETECT_` constants
      另请参阅:
        `setAutodetectModeName(String)`, `AUTODETECT_ALL`, `AUTODETECT_ASSEMBLER`, `AUTODETECT_MBEAN`, `AUTODETECT_NONE`

    - #### setAutodetectModeName

          public void setAutodetectModeName(String constantName)

      Set the autodetection mode to use by name.
      抛出:
        `IllegalArgumentException` - if the supplied value is not resolvable to one of the `AUTODETECT_` constants or is `null`
      另请参阅:
        `setAutodetectMode(int)`, `AUTODETECT_ALL`, `AUTODETECT_ASSEMBLER`, `AUTODETECT_MBEAN`, `AUTODETECT_NONE`

    - #### setAllowEagerInit

          public void setAllowEagerInit(boolean allowEagerInit)

      Specify whether to allow eager initialization of candidate beans when autodetecting MBeans in the Spring application context.

      Default is "false", respecting lazy-init flags on bean definitions. Switch this to "true" in order to search lazy-init beans as well, including FactoryBean-produced objects that haven't been initialized yet.

    - #### setAssembler

          public void setAssembler(MBeanInfoAssembler assembler)

      Set the implementation of the `MBeanInfoAssembler` interface to use for this exporter. Default is a `SimpleReflectiveMBeanInfoAssembler`.

      The passed-in assembler can optionally implement the `AutodetectCapableMBeanInfoAssembler` interface, which enables it to participate in the exporter's MBean autodetection process.

      另请参阅:
        `SimpleReflectiveMBeanInfoAssembler`, `AutodetectCapableMBeanInfoAssembler`, `MetadataMBeanInfoAssembler`, `setAutodetect(boolean)`

    - #### setNamingStrategy

          public void setNamingStrategy(ObjectNamingStrategy namingStrategy)

      Set the implementation of the `ObjectNamingStrategy` interface to use for this exporter. Default is a `KeyNamingStrategy`.
      另请参阅:
        `KeyNamingStrategy`, `MetadataNamingStrategy`

    - #### setEnsureUniqueRuntimeObjectNames

          public void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)

      Indicates whether Spring should ensure that `ObjectNames` generated by the configured `ObjectNamingStrategy` for runtime-registered MBeans (`registerManagedResource(java.lang.Object)`) should get modified: to ensure uniqueness for every instance of a managed `Class`.

      The default value is `true`.

      另请参阅:
        `registerManagedResource(java.lang.Object)`, `JmxUtils.appendIdentityToObjectName(javax.management.ObjectName, Object)`

    - #### setExposeManagedResourceClassLoader

          public void setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader)

      Indicates whether or not the managed resource should be exposed on the `thread context ClassLoader` before allowing any invocations on the MBean to occur.

      The default value is `true`, exposing a `SpringModelMBean` which performs thread context ClassLoader management. Switch this flag off to expose a standard JMX `RequiredModelMBean`.

    - #### setExcludedBeans

          public void setExcludedBeans(String... excludedBeans)

      Set the list of names for beans that should be excluded from autodetection.

    - #### addExcludedBean

          public void addExcludedBean(String excludedBean)

      Add the name of bean that should be excluded from autodetection.

    - #### setListeners

          public void setListeners(MBeanExporterListener... listeners)

      Set the `MBeanExporterListener`s that should be notified of MBean registration and unregistration events.
      另请参阅:
        `MBeanExporterListener`

    - #### setNotificationListeners

          public void setNotificationListeners(NotificationListenerBean... notificationListeners)

      Set the `NotificationListenerBeans` containing the `NotificationListeners` that will be registered with the `MBeanServer`.
      另请参阅:
        `setNotificationListenerMappings(java.util.Map)`, `NotificationListenerBean`

    - #### setNotificationListenerMappings

          public void setNotificationListenerMappings(Map<?,? extends NotificationListener> listeners)

      Set the `NotificationListeners` to register with the `MBeanServer`.

      The key of each entry in the `Map` is a `String` representation of the `ObjectName` or the bean name of the MBean the listener should be registered for. Specifying an asterisk (`*`) for a key will cause the listener to be associated with all MBeans registered by this class at startup time.

      The value of each entry is the `NotificationListener` to register. For more advanced options such as registering `NotificationFilters` and handback objects see `setNotificationListeners(NotificationListenerBean[])`.

    - #### setBeanClassLoader

          public void setBeanClassLoader(ClassLoader classLoader)

      指定者:
        `setBeanClassLoader` 在接口中 `org.springframework.beans.factory.BeanClassLoaderAware`

    - #### setBeanFactory

          public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

      This callback is only required for resolution of bean names in the `"beans"` `Map` and for autodetection of MBeans (in the latter case, a `ListableBeanFactory` is required).
      指定者:
        `setBeanFactory` 在接口中 `org.springframework.beans.factory.BeanFactoryAware`
      另请参阅:
        `setBeans(java.util.Map<java.lang.String, java.lang.Object>)`, `setAutodetect(boolean)`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`

    - #### afterSingletonsInstantiated

          public void afterSingletonsInstantiated()

      Kick off bean registration automatically after the regular singleton instantiation phase.
      指定者:
        `afterSingletonsInstantiated` 在接口中 `org.springframework.beans.factory.SmartInitializingSingleton`
      另请参阅:
        `registerBeans()`

    - #### destroy

          public void destroy()

      Unregisters all beans that this exported has exposed via JMX when the enclosing `ApplicationContext` is destroyed.
      指定者:
        `destroy` 在接口中 `org.springframework.beans.factory.DisposableBean`

    - #### registerManagedResource

          public ObjectName registerManagedResource(Object managedResource)
                                             throws MBeanExportException

      从接口复制的说明: `MBeanExportOperations`
      Register the supplied resource with JMX. If the resource is not a valid MBean already, Spring will generate a management interface for it. The exact interface generated will depend on the implementation and its configuration. This call also generates an `ObjectName` for the managed resource and returns this to the caller.
      指定者:
        `registerManagedResource` 在接口中 `MBeanExportOperations`
      参数:
        `managedResource` - the resource to expose via JMX
      返回:
        the `ObjectName` under which the resource was exposed
      抛出:
        `MBeanExportException` - if Spring is unable to generate an `ObjectName` or register the MBean

    - #### registerManagedResource

          public void registerManagedResource(Object managedResource,
                                              ObjectName objectName)
                                       throws MBeanExportException

      从接口复制的说明: `MBeanExportOperations`
      Register the supplied resource with JMX. If the resource is not a valid MBean already, Spring will generate a management interface for it. The exact interface generated will depend on the implementation and its configuration.
      指定者:
        `registerManagedResource` 在接口中 `MBeanExportOperations`
      参数:
        `managedResource` - the resource to expose via JMX
        `objectName` - the `ObjectName` under which to expose the resource
      抛出:
        `MBeanExportException` - if Spring is unable to register the MBean

    - #### unregisterManagedResource

          public void unregisterManagedResource(ObjectName objectName)

      从接口复制的说明: `MBeanExportOperations`
      Remove the specified MBean from the underlying MBeanServer registry.
      指定者:
        `unregisterManagedResource` 在接口中 `MBeanExportOperations`
      参数:
        `objectName` - the `ObjectName` of the resource to remove

    - #### registerBeans

          protected void registerBeans()

      Register the defined beans with the `MBeanServer`.

      Each bean is exposed to the `MBeanServer` via a `ModelMBean`. The actual implementation of the `ModelMBean` interface used depends on the implementation of the `ModelMBeanProvider` interface that is configured. By default the `RequiredModelMBean` class that is supplied with all JMX implementations is used.

      The management interface produced for each bean is dependent on the `MBeanInfoAssembler` implementation being used. The `ObjectName` given to each bean is dependent on the implementation of the `ObjectNamingStrategy` interface being used.

    - #### isBeanDefinitionLazyInit

          protected boolean isBeanDefinitionLazyInit(org.springframework.beans.factory.ListableBeanFactory beanFactory,
                                                     String beanName)

      Return whether the specified bean definition should be considered as lazy-init.
      参数:
        `beanFactory` - the bean factory that is supposed to contain the bean definition
        `beanName` - the name of the bean to check
      另请参阅:
        `ConfigurableListableBeanFactory.getBeanDefinition(java.lang.String)`, `BeanDefinition.isLazyInit()`

    - #### registerBeanNameOrInstance

          protected ObjectName registerBeanNameOrInstance(Object mapValue,
                                                          String beanKey)
                                                   throws MBeanExportException

      Register an individual bean with the `MBeanServer`.

      This method is responsible for deciding how a bean should be exposed to the `MBeanServer`. Specifically, if the supplied `mapValue` is the name of a bean that is configured for lazy initialization, then a proxy to the resource is registered with the `MBeanServer` so that the lazy load behavior is honored. If the bean is already an MBean then it will be registered directly with the `MBeanServer` without any intervention. For all other beans or bean names, the resource itself is registered with the `MBeanServer` directly.

      参数:
        `mapValue` - the value configured for this bean in the beans map; may be either the `String` name of a bean, or the bean itself
        `beanKey` - the key associated with this bean in the beans map
      返回:
        the `ObjectName` under which the resource was registered
      抛出:
        `MBeanExportException` - if the export failed
      另请参阅:
        `setBeans(java.util.Map<java.lang.String, java.lang.Object>)`, `registerBeanInstance(java.lang.Object, java.lang.String)`, `registerLazyInit(java.lang.String, java.lang.String)`

    - #### getObjectName

          protected ObjectName getObjectName(Object bean,
                                             @Nullable
                                             String beanKey)
                                      throws MalformedObjectNameException

      Retrieve the `ObjectName` for a bean.

      If the bean implements the `SelfNaming` interface, then the `ObjectName` will be retrieved using `SelfNaming.getObjectName()`. Otherwise, the configured `ObjectNamingStrategy` is used.

      参数:
        `bean` - the name of the bean in the `BeanFactory`
        `beanKey` - the key associated with the bean in the beans map
      返回:
        the `ObjectName` for the supplied bean
      抛出:
        `MalformedObjectNameException` - if the retrieved `ObjectName` is malformed

    - #### isMBean

          protected boolean isMBean(@Nullable
                                    Class<?> beanClass)

      Determine whether the given bean class qualifies as an MBean as-is.

      The default implementation delegates to `JmxUtils.isMBean(java.lang.Class<?>)`, which checks for `DynamicMBean` classes as well as classes with corresponding "*MBean" interface (Standard MBeans) or corresponding "*MXBean" interface (Java 6 MXBeans).

      参数:
        `beanClass` - the bean class to analyze
      返回:
        whether the class qualifies as an MBean
      另请参阅:
        `JmxUtils.isMBean(Class)`

    - #### adaptMBeanIfPossible

          @Nullable
          protected DynamicMBean adaptMBeanIfPossible(Object bean)
                                                          throws JMException

      Build an adapted MBean for the given bean instance, if possible.

      The default implementation builds a JMX 1.2 StandardMBean for the target's MBean/MXBean interface in case of an AOP proxy, delegating the interface's management operations to the proxy.

      参数:
        `bean` - the original bean instance
      返回:
        the adapted MBean, or `null` if not possible
      抛出:
        `JMException`

    - #### createAndConfigureMBean

          protected ModelMBean createAndConfigureMBean(Object managedResource,
                                                       String beanKey)
                                                throws MBeanExportException

      Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.
      参数:
        `managedResource` - the resource that is to be exported as an MBean
        `beanKey` - the key associated with the managed bean
      抛出:
        `MBeanExportException`
      另请参阅:
        `createModelMBean()`, `getMBeanInfo(Object, String)`

    - #### createModelMBean

          protected ModelMBean createModelMBean()
                                         throws MBeanException

      Create an instance of a class that implements `ModelMBean`.

      This method is called to obtain a `ModelMBean` instance to use when registering a bean. This method is called once per bean during the registration phase and must return a new instance of `ModelMBean`

      返回:
        a new instance of a class that implements `ModelMBean`
      抛出:
        `MBeanException` - if creation of the ModelMBean failed

    - #### onRegister

          protected void onRegister(ObjectName objectName)

      Called when an MBean is registered. Notifies all registered `MBeanExporterListeners` of the registration event.

      Please note that if an `MBeanExporterListener` throws a (runtime) exception when notified, this will essentially interrupt the notification process and any remaining listeners that have yet to be notified will not (obviously) receive the `MBeanExporterListener.mbeanRegistered(javax.management.ObjectName)` callback.

      覆盖:
        `onRegister` 在类中 `MBeanRegistrationSupport`
      参数:
        `objectName` - the `ObjectName` of the registered MBean

    - #### onUnregister

          protected void onUnregister(ObjectName objectName)

      Called when an MBean is unregistered. Notifies all registered `MBeanExporterListeners` of the unregistration event.

      Please note that if an `MBeanExporterListener` throws a (runtime) exception when notified, this will essentially interrupt the notification process and any remaining listeners that have yet to be notified will not (obviously) receive the `MBeanExporterListener.mbeanUnregistered(javax.management.ObjectName)` callback.

      覆盖:
        `onUnregister` 在类中 `MBeanRegistrationSupport`
      参数:
        `objectName` - the `ObjectName` of the unregistered MBean