@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jmx;
@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jmx;
import javax.management.MBeanServer ;
import org.springframework.beans.factory.BeanFactory ;
import org.springframework.beans.factory.FactoryBean ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass ;
@ -36,6 +37,10 @@ import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
@@ -36,6 +37,10 @@ import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
import org.springframework.jmx.export.annotation.AnnotationMBeanExporter ;
import org.springframework.jmx.export.naming.ObjectNamingStrategy ;
import org.springframework.jmx.support.MBeanServerFactoryBean ;
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean ;
import org.springframework.jndi.JndiObjectFactoryBean ;
import org.springframework.util.Assert ;
import org.springframework.util.ClassUtils ;
/ * *
* { @link EnableAutoConfiguration Auto - configuration } to enable / disable Spring ' s
@ -81,10 +86,8 @@ public class JmxAutoConfiguration {
@@ -81,10 +86,8 @@ public class JmxAutoConfiguration {
@Bean
@ConditionalOnMissingBean ( MBeanServer . class )
public MBeanServerFactoryBean mbeanServer ( ) {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean ( ) ;
factory . setLocateExistingServerIfPossible ( true ) ;
return factory ;
public MBeanServer mbeanServer ( ) {
return SpecificPlatform . get ( ) . getMBeanServer ( ) ;
}
@EnableMBeanExport ( defaultDomain = "${spring.jmx.default_domain:}" , server = "${spring.jmx.server:mbeanServer}" )
@ -92,4 +95,65 @@ public class JmxAutoConfiguration {
@@ -92,4 +95,65 @@ public class JmxAutoConfiguration {
}
// Copied and adapted from MBeanExportConfiguration
private static enum SpecificPlatform {
WEBLOGIC ( "weblogic.management.Helper" ) {
@Override
public FactoryBean < ? > getMBeanServerFactory ( ) {
JndiObjectFactoryBean factory = new JndiObjectFactoryBean ( ) ;
factory . setJndiName ( "java:comp/env/jmx/runtime" ) ;
return factory ;
}
} ,
WEBSPHERE ( "com.ibm.websphere.management.AdminServiceFactory" ) {
@Override
public FactoryBean < MBeanServer > getMBeanServerFactory ( ) {
return new WebSphereMBeanServerFactoryBean ( ) ;
}
} ,
GENERIC ( "org.springframework.jmx.support.MBeanServerFactoryBean" ) {
@Override
public FactoryBean < MBeanServer > getMBeanServerFactory ( ) {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean ( ) ;
factory . setLocateExistingServerIfPossible ( true ) ;
factory . afterPropertiesSet ( ) ;
return factory ;
}
} ;
private final String identifyingClass ;
private SpecificPlatform ( String identifyingClass ) {
this . identifyingClass = identifyingClass ;
}
public MBeanServer getMBeanServer ( ) {
Object server ;
try {
server = getMBeanServerFactory ( ) . getObject ( ) ;
Assert . isInstanceOf ( MBeanServer . class , server ) ;
return ( MBeanServer ) server ;
}
catch ( Exception ex ) {
throw new IllegalStateException ( ex ) ;
}
}
protected abstract FactoryBean < ? > getMBeanServerFactory ( ) ;
public static SpecificPlatform get ( ) {
ClassLoader classLoader = MBeanExportConfiguration . class . getClassLoader ( ) ;
for ( SpecificPlatform environment : values ( ) ) {
if ( ClassUtils . isPresent ( environment . identifyingClass , classLoader ) ) {
return environment ;
}
}
return null ;
}
}
}