Affects: Spring Boot 2.2.11 (but most likely the current version as well, the code is the same)
JmxAutoConfiguration configures the created ParentAwareNamingStrategy based on spring.jmx.unique-names (default: false) to add an "identity" field to the ObjectName. However, it does not configure the created AnnotationMBeanExporter, whose super class MBeanExporter has the same functionality (which is unfortunately enabled by default), in the same way.
This leads to an situation, if spring.jmx.unique-names is not defined or false, where MBeans registered via annotations (@ManagedResource etc.) don't get the "identity" field, while MBeans implementing SelfNaming, created dynamically by the application and registered with MBeanExporter#registerManagedResource(Object) get an "identity" field.
This is inconsistent and cannot be changed by configuration alone currently. It can be resolved programmatically by creating an own, differently configured, AnnotationMBeanExporter bean or by using MBeanExporter#registerManagedResource(Object, ObjectName) instead, where ObjectName must be obtained manually from SelfNaming#getObjectName before.
Comment From: wilkinsona
Thanks, @rschuetz. We should probably apply spring.jmx.unique-names to the auto-configured AnnotationMBeanExporter. We'll need to consider the timing of this as it could be a breaking change for some, although I suspect it's unlikely that anyone is intentionally relying on the current, inconsistent behaviour.