Explicit note on FactoryBean resolution with MBeanExporter

Closes gh-21676
This commit is contained in:
Juergen Hoeller 2023-08-08 20:11:28 +02:00
parent 8973d1ad8a
commit d58e48d9f5
1 changed files with 10 additions and 7 deletions

View File

@ -183,18 +183,21 @@ as the following example shows:
If you configure a bean with an `MBeanExporter` that is also configured for lazy If you configure a bean with an `MBeanExporter` that is also configured for lazy
initialization, the `MBeanExporter` does not break this contract and avoids initialization, the `MBeanExporter` does not break this contract and avoids
instantiating the bean. Instead, it registers a proxy with the `MBeanServer` and instantiating the bean. Instead, it registers a proxy with the `MBeanServer` and defers
defers obtaining the bean from the container until the first invocation on the proxy obtaining the bean from the container until the first invocation on the proxy occurs.
occurs.
This also affects `FactoryBean` resolution where `MBeanExporter` will regularly
introspect the produced object, effectively triggering `FactoryBean.getObject()`.
In order to avoid this, mark the corresponding bean definition as lazy-init.
[[jmx-exporting-auto]] [[jmx-exporting-auto]]
== Automatic Registration of MBeans == Automatic Registration of MBeans
Any beans that are exported through the `MBeanExporter` and are already valid MBeans are Any beans that are exported through the `MBeanExporter` and are already valid MBeans
registered as-is with the `MBeanServer` without further intervention from Spring. You can cause MBeans are registered as-is with the `MBeanServer` without further intervention from Spring.
to be automatically detected by the `MBeanExporter` by setting the `autodetect` You can cause MBeans to be automatically detected by the `MBeanExporter` by setting
property to `true`, as the following example shows: the `autodetect` property to `true`, as the following example shows:
[source,xml,indent=0,subs="verbatim,quotes"] [source,xml,indent=0,subs="verbatim,quotes"]
---- ----