@ -29,12 +29,12 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean ;
import org.springframework.beans.factory.InitializingBean ;
import org.springframework.boot.context.event.ApplicationReadyEvent ;
import org.springframework.boot.web. servlet.context.ServletWebServerApplicationContex t;
import org.springframework.boot.web. context.WebServerInitializedEven t;
import org.springframework.context.ApplicationContext ;
import org.springframework.context.ApplicationContextAware ;
import org.springframework.context.ApplicationListener ;
import org.springframework.context.ConfigurableApplicationContext ;
import org.springframework.context.EnvironmentAware ;
import org.springframework.context.event.EventListener ;
import org.springframework.core.env.Environment ;
import org.springframework.core.env.StandardEnvironment ;
import org.springframework.util.Assert ;
@ -49,7 +49,7 @@ import org.springframework.util.Assert;
* /
public class SpringApplicationAdminMXBeanRegistrar
implements ApplicationContextAware , EnvironmentAware , InitializingBean ,
DisposableBean , ApplicationListener < ApplicationReadyEvent > {
DisposableBean {
private static final Log logger = LogFactory . getLog ( SpringApplicationAdmin . class ) ;
@ -61,6 +61,8 @@ public class SpringApplicationAdminMXBeanRegistrar
private boolean ready = false ;
private boolean embeddedWebApplication = false ;
public SpringApplicationAdminMXBeanRegistrar ( String name )
throws MalformedObjectNameException {
this . objectName = new ObjectName ( name ) ;
@ -79,13 +81,20 @@ public class SpringApplicationAdminMXBeanRegistrar
this . environment = environment ;
}
@ Override
public void onApplication Event( ApplicationReadyEvent event ) {
@ EventListener
public void onApplication Ready Event( ApplicationReadyEvent event ) {
if ( this . applicationContext . equals ( event . getApplicationContext ( ) ) ) {
this . ready = true ;
}
}
@EventListener
public void onWebServerInitializedEvent ( WebServerInitializedEvent event ) {
if ( this . applicationContext . equals ( event . getApplicationContext ( ) ) ) {
this . embeddedWebApplication = true ;
}
}
@Override
public void afterPropertiesSet ( ) throws Exception {
MBeanServer server = ManagementFactory . getPlatformMBeanServer ( ) ;
@ -110,8 +119,7 @@ public class SpringApplicationAdminMXBeanRegistrar
@Override
public boolean isEmbeddedWebApplication ( ) {
return ( SpringApplicationAdminMXBeanRegistrar . this . applicationContext ! = null
& & SpringApplicationAdminMXBeanRegistrar . this . applicationContext instanceof ServletWebServerApplicationContext ) ;
return SpringApplicationAdminMXBeanRegistrar . this . embeddedWebApplication ;
}
@Override