Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring JMX Annotation inheritance support is inconsistent (or at least difficult in some situations) [SPR-5039] #9714

Closed
spring-projects-issues opened this issue Jul 25, 2008 · 0 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 25, 2008

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:

<bean id="connectionPool" class="company.ConnPool" destroy-method="shutdown">
</bean>

<bean id="dispatchConnection" factory-bean="connectionPool" factory-method="getDefDispatchConn" scope="prototype" />

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:

Referenced from: commits 8f6a42b

3 votes, 3 watchers

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant