Skip to content

Commit

Permalink
Defensive MBeanExporterHelper Registration
Browse files Browse the repository at this point in the history
If the initializer is somehow called more than once, context
initialization will fail with default Boot 2.1 settings, which
do not allow bean overrides.
  • Loading branch information
garyrussell authored and artembilan committed Oct 11, 2018
1 parent 58fe203 commit 49f0a33
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
Expand Down Expand Up @@ -27,6 +27,7 @@
* The JMX Integration infrastructure {@code beanFactory} initializer.
*
* @author Artem Bilan
* @author Gary Russell
* @since 4.0
*/
public class JmxIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
Expand All @@ -39,7 +40,8 @@ public void initialize(ConfigurableListableBeanFactory beanFactory) throws Beans
}

private void registerMBeanExporterHelperIfNecessary(ConfigurableListableBeanFactory beanFactory) {
if (beanFactory.getBeanNamesForType(IntegrationMBeanExporter.class, false, false).length > 0) {
if (!beanFactory.containsBean(MBEAN_EXPORTER_HELPER_BEAN_NAME)
&& beanFactory.getBeanNamesForType(IntegrationMBeanExporter.class, false, false).length > 0) {
((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(MBEAN_EXPORTER_HELPER_BEAN_NAME,
new RootBeanDefinition(MBeanExporterHelper.class));
}
Expand Down

0 comments on commit 49f0a33

Please sign in to comment.