Spring JMX Annotation inheritance support is inconsistent (or at least difficult in some situations) [SPR-5039] #9714
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Tom Mack opened SPR-5039 and commented
Here's my situation, I have an inteface "Connection", aABC "ConnectionBase", and several concrete class "SpecificXXXConnection" (note, none of these classes override methods in the base class). For historical reasons, the connections are produced by a static method on a factory class. So each connection bean is declared using the factory-method syntax. For example:
The getDefDispatchConn method is declared to return a "Connection".
So my first problem is that the MBeanExporter.autodetect(AutodetectCallback) method only looks for annotations on the beanFactory.getType() type (which is going to be the interface). This is alright (even though in the !laxyInit case, it could use the actual instance for the include check), so I put my
@ManagedResource
and@ManagedAttribute
annotations on the interface.But then, things still weren't working. I found that AnnotationJmxAttributeSource.getManagedResource(Class) uses the Class.getAnnotation method(Class) method (and at this point we're using the Class of the actual instance, SpecificConnection). This causes a problem because it will not find the annotation on the interface (or on the base class, for that matter). So, I overrode this method to use AnnotationUtils.findAnnotation. This got me closer. But now, none of the attributes were being found. Because it doesn't seem like findAnnotation(Method,Class) can find annotations on interfaces, I had to move the
@ManagedAttribute
annotations to the ABC.So in summary, I had to place a
@ManagedResource
on the interface to get the bean included in the first place, then this annotation must also be on each concrete class OR getManagedResource muse be overridden, and finally the attributes may not be annotated at the interface level.Obviously taking the FactoryBean out of the picture would simplify things, but it seems like something here could be improved.
Affects: 2.5.4
Issue Links:
@ManagedXYZ
on interfacesReferenced from: commits 8f6a42b
3 votes, 3 watchers
The text was updated successfully, but these errors were encountered: