简体   繁体   中英

Spring-Boot: Jmx annotation not working in library

I have a Spring-Boot application that just have a simple rest controller. On this controller, I added the jmx annotations @ManagedResource and @ManagedOperation and it is working fine. It is correctly exposed in Jmx. This application depends on a "global-commons" library to share many basic functionality to all of our modules.

But if I add the same annotations to a class in this library, it is ignored! And before you ask, yes the library is imported with the latest change. There is no error or warning message in the logs.

I am configuring all my beans using an xml file. Both classes are beans defined in the same file. One is a @RestController. The other one is a simple utility class.

Any idea?

Make sure the classes from the global-commons library as managed by Spring. As long as none of the classes in the library are managed by Spring, the annotions don't have any effect.

I found the problems: The bean that was not working was defined as an "inner" bean:

<bean id="imMetrics" class="com.imetrik.global.common.metrics.ImGlobalMetrics" init-method="init">
    ...
    <property name="reporterList">
        <util:list>
            <bean id="jmxReporter" class="com.imetrik.global.common.metrics.reporters.ImJmxReporter">
                <property name="registryId" value="metricRegistry1"/>
                <property name="durationUnit" value="SECONDS"/>
                <property name="rateUnit" value="SECONDS"/>
                <property name="domain" value="com.imetrik.global.metric"/>
            </bean>
        </util:list>
    </property>
</bean>

The annotated beans is "jmxReporter".

But if I put it outside as a normal "first level" bean and use a reference instead, it is working. But it is annoying! Is there a way to make it work even as a inner beans?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM