Skip to content

Commit 4a27a98

Browse files
committed
Spring's JMX support can rely on native MXBean detection on Java 6+
Issue: SPR-12574 (cherry picked from commit 0919a15)
1 parent 929c596 commit 4a27a98

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -263,20 +263,13 @@ public void prepare() {
263263
}
264264
this.invocationHandler = null;
265265
if (this.useStrictCasing) {
266-
// Use the JDK's own MBeanServerInvocationHandler,
267-
// in particular for native MXBean support on Java 6.
268-
if (JmxUtils.isMXBeanSupportAvailable()) {
269-
this.invocationHandler =
270-
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
271-
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
272-
}
273-
else {
274-
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
275-
}
266+
// Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support.
267+
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
268+
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
276269
}
277270
else {
278-
// Non-strict casing can only be achieved through custom
279-
// invocation handling. Only partial MXBean support available!
271+
// Non-strict casing can only be achieved through custom invocation handling.
272+
// Only partial MXBean support available!
280273
retrieveMBeanInfo();
281274
}
282275
}

spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java

+6-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@
2222
import java.util.Hashtable;
2323
import java.util.List;
2424
import javax.management.DynamicMBean;
25+
import javax.management.JMX;
2526
import javax.management.MBeanParameterInfo;
2627
import javax.management.MBeanServer;
2728
import javax.management.MBeanServerFactory;
28-
import javax.management.MXBean;
2929
import javax.management.MalformedObjectNameException;
3030
import javax.management.ObjectName;
3131

@@ -59,16 +59,6 @@ public abstract class JmxUtils {
5959
*/
6060
private static final String MBEAN_SUFFIX = "MBean";
6161

62-
/**
63-
* Suffix used to identify a Java 6 MXBean interface.
64-
*/
65-
private static final String MXBEAN_SUFFIX = "MXBean";
66-
67-
private static final String MXBEAN_ANNOTATION_CLASS_NAME = "javax.management.MXBean";
68-
69-
70-
private static final boolean mxBeanAnnotationAvailable =
71-
ClassUtils.isPresent(MXBEAN_ANNOTATION_CLASS_NAME, JmxUtils.class.getClassLoader());
7262

7363
private static final Log logger = LogFactory.getLog(JmxUtils.class);
7464

@@ -304,14 +294,7 @@ public static Class<?> getMXBeanInterface(Class<?> clazz) {
304294
}
305295
Class<?>[] implementedInterfaces = clazz.getInterfaces();
306296
for (Class<?> iface : implementedInterfaces) {
307-
boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX);
308-
if (mxBeanAnnotationAvailable) {
309-
Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface);
310-
if (checkResult != null) {
311-
isMxBean = checkResult;
312-
}
313-
}
314-
if (isMxBean) {
297+
if (JMX.isMXBeanInterface(iface)) {
315298
return iface;
316299
}
317300
}
@@ -322,21 +305,11 @@ public static Class<?> getMXBeanInterface(Class<?> clazz) {
322305
* Check whether MXBean support is available, i.e. whether we're running
323306
* on Java 6 or above.
324307
* @return {@code true} if available; {@code false} otherwise
308+
* @deprecated as of Spring 4.0, since Java 6 is required anyway now
325309
*/
310+
@Deprecated
326311
public static boolean isMXBeanSupportAvailable() {
327-
return mxBeanAnnotationAvailable;
328-
}
329-
330-
331-
/**
332-
* Inner class to avoid a Java 6 dependency.
333-
*/
334-
private static class MXBeanChecker {
335-
336-
public static Boolean evaluateMXBeanAnnotation(Class<?> iface) {
337-
MXBean mxBean = iface.getAnnotation(MXBean.class);
338-
return (mxBean != null ? mxBean.value() : null);
339-
}
312+
return true;
340313
}
341314

342315
}

0 commit comments

Comments
 (0)