From 4a27a9870276dc78bcf04f0b1a6ed322c6c8cce6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 29 Dec 2014 18:59:07 +0100 Subject: [PATCH] Spring's JMX support can rely on native MXBean detection on Java 6+ Issue: SPR-12574 (cherry picked from commit 0919a15) --- .../jmx/access/MBeanClientInterceptor.java | 19 +++------ .../springframework/jmx/support/JmxUtils.java | 39 +++---------------- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java b/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java index f7e2f7db39..b07c160eb4 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -263,20 +263,13 @@ public class MBeanClientInterceptor } this.invocationHandler = null; if (this.useStrictCasing) { - // Use the JDK's own MBeanServerInvocationHandler, - // in particular for native MXBean support on Java 6. - if (JmxUtils.isMXBeanSupportAvailable()) { - this.invocationHandler = - new MBeanServerInvocationHandler(this.serverToUse, this.objectName, - (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); - } - else { - this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName); - } + // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. + this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, + (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { - // Non-strict casing can only be achieved through custom - // invocation handling. Only partial MXBean support available! + // Non-strict casing can only be achieved through custom invocation handling. + // Only partial MXBean support available! retrieveMBeanInfo(); } } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java index a4f84b0dd0..2a29683aad 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ import java.lang.reflect.Method; import java.util.Hashtable; import java.util.List; import javax.management.DynamicMBean; +import javax.management.JMX; import javax.management.MBeanParameterInfo; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; -import javax.management.MXBean; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -59,16 +59,6 @@ public abstract class JmxUtils { */ private static final String MBEAN_SUFFIX = "MBean"; - /** - * Suffix used to identify a Java 6 MXBean interface. - */ - private static final String MXBEAN_SUFFIX = "MXBean"; - - private static final String MXBEAN_ANNOTATION_CLASS_NAME = "javax.management.MXBean"; - - - private static final boolean mxBeanAnnotationAvailable = - ClassUtils.isPresent(MXBEAN_ANNOTATION_CLASS_NAME, JmxUtils.class.getClassLoader()); private static final Log logger = LogFactory.getLog(JmxUtils.class); @@ -304,14 +294,7 @@ public abstract class JmxUtils { } Class[] implementedInterfaces = clazz.getInterfaces(); for (Class iface : implementedInterfaces) { - boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX); - if (mxBeanAnnotationAvailable) { - Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface); - if (checkResult != null) { - isMxBean = checkResult; - } - } - if (isMxBean) { + if (JMX.isMXBeanInterface(iface)) { return iface; } } @@ -322,21 +305,11 @@ public abstract class JmxUtils { * Check whether MXBean support is available, i.e. whether we're running * on Java 6 or above. * @return {@code true} if available; {@code false} otherwise + * @deprecated as of Spring 4.0, since Java 6 is required anyway now */ + @Deprecated public static boolean isMXBeanSupportAvailable() { - return mxBeanAnnotationAvailable; - } - - - /** - * Inner class to avoid a Java 6 dependency. - */ - private static class MXBeanChecker { - - public static Boolean evaluateMXBeanAnnotation(Class iface) { - MXBean mxBean = iface.getAnnotation(MXBean.class); - return (mxBean != null ? mxBean.value() : null); - } + return true; } }