Add MBeanServer @Bean in case it is needed

Anywhere that an MBeanServer is needed it should be
created @Conditionally, so that user can exclude the
JmxAutoConfiguration and still get the other JMX
behaviours automatically.
pull/1052/head
Dave Syer 11 years ago
parent 1a5c4f88b4
commit aa30fdba18

@ -24,10 +24,12 @@ import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -61,4 +63,11 @@ public class EndpointMBeanExportAutoConfiguration {
return mbeanExporter; return mbeanExporter;
} }
@Bean
@ConditionalOnMissingBean(MBeanServer.class)
public MBeanServerFactoryBean mbeanServer() {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
factory.setLocateExistingServerIfPossible(true);
return factory;
}
} }

@ -16,15 +16,19 @@
package org.springframework.boot.autoconfigure.integration; package org.springframework.boot.autoconfigure.integration;
import javax.management.MBeanServer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport; import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
import org.springframework.integration.jmx.config.IntegrationMBeanExportConfiguration; import org.springframework.integration.jmx.config.IntegrationMBeanExportConfiguration;
import org.springframework.jmx.support.MBeanServerFactoryBean;
/** /**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
@ -52,4 +56,12 @@ public class IntegrationAutoConfiguration {
protected static class IntegrationJmxConfiguration { protected static class IntegrationJmxConfiguration {
} }
@Bean
@ConditionalOnMissingBean(MBeanServer.class)
public MBeanServerFactoryBean mbeanServer() {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
factory.setLocateExistingServerIfPossible(true);
return factory;
}
} }

Loading…
Cancel
Save