Skip to content

Commit 49f0a33

Browse files
garyrussellartembilan
authored andcommitted
Defensive MBeanExporterHelper Registration
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.
1 parent 58fe203 commit 49f0a33

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxIntegrationConfigurationInitializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 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.
@@ -27,6 +27,7 @@
2727
* The JMX Integration infrastructure {@code beanFactory} initializer.
2828
*
2929
* @author Artem Bilan
30+
* @author Gary Russell
3031
* @since 4.0
3132
*/
3233
public class JmxIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
@@ -39,7 +40,8 @@ public void initialize(ConfigurableListableBeanFactory beanFactory) throws Beans
3940
}
4041

4142
private void registerMBeanExporterHelperIfNecessary(ConfigurableListableBeanFactory beanFactory) {
42-
if (beanFactory.getBeanNamesForType(IntegrationMBeanExporter.class, false, false).length > 0) {
43+
if (!beanFactory.containsBean(MBEAN_EXPORTER_HELPER_BEAN_NAME)
44+
&& beanFactory.getBeanNamesForType(IntegrationMBeanExporter.class, false, false).length > 0) {
4345
((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(MBEAN_EXPORTER_HELPER_BEAN_NAME,
4446
new RootBeanDefinition(MBeanExporterHelper.class));
4547
}

0 commit comments

Comments
 (0)