diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java index 171b362893..3c18ab99b9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java @@ -55,7 +55,7 @@ public @interface EnableIntegrationManagement { * components. Overrides {@link #defaultCountsEnabled()} for matching bean names. * @return the patterns. */ - String[] countsEnabled() default ""; + String[] countsEnabled() default "*"; /** * A list of simple patterns for component names for which message statistics will be @@ -74,7 +74,7 @@ public @interface EnableIntegrationManagement { * components. * @return the patterns. */ - String[] statsEnabled() default ""; + String[] statsEnabled() default "*"; /** * The default setting for enabling counts when a bean name is not matched by diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java index 4f01e816eb..ca1de73db9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java @@ -93,14 +93,14 @@ public class IntegrationManagementConfiguration implements ImportAware, Environm configurer.setEnabledCountsPatterns(patterns.toArray(new String[patterns.size()])); } - private void setupStatsEnabledNamePatterns(IntegrationManagementConfigurer exporter) { + private void setupStatsEnabledNamePatterns(IntegrationManagementConfigurer configurer) { List patterns = new ArrayList(); String[] statsEnabled = this.attributes.getStringArray("statsEnabled"); for (String managedComponent : statsEnabled) { String pattern = this.environment.resolvePlaceholders(managedComponent); patterns.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(pattern))); } - exporter.setEnabledStatsPatterns(patterns.toArray(new String[patterns.size()])); + configurer.setEnabledStatsPatterns(patterns.toArray(new String[patterns.size()])); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagementConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagementConfigurer.java index c44fe3d493..d73151f1e2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagementConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagementConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.support.management; import java.util.Arrays; @@ -26,6 +27,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.util.Assert; import org.springframework.util.PatternMatchUtils; +import org.springframework.util.StringUtils; /** @@ -51,7 +53,7 @@ public class IntegrationManagementConfigurer implements SmartInitializingSinglet private Boolean defaultStatsEnabled = false; - private MetricsFactory metricsFactory = new DefaultMetricsFactory(); + private MetricsFactory metricsFactory; private String metricsFactoryBeanName; @@ -72,6 +74,8 @@ public class IntegrationManagementConfigurer implements SmartInitializingSinglet /** * Set a metrics factory. + * Has a precedence over {@link #metricsFactoryBeanName}. + * Defaults to {@link DefaultMetricsFactory}. * @param metricsFactory the factory. * @since 4.2 */ @@ -79,6 +83,12 @@ public class IntegrationManagementConfigurer implements SmartInitializingSinglet this.metricsFactory = metricsFactory; } + /** + * Set a metrics factory bean name. + * Is used if {@link #metricsFactory} isn't specified. + * @param metricsFactory the factory. + * @since 4.2 + */ public void setMetricsFactoryBeanName(String metricsFactory) { this.metricsFactoryBeanName = metricsFactory; } @@ -117,7 +127,7 @@ public class IntegrationManagementConfigurer implements SmartInitializingSinglet * @param enabledStatsPatterns the patterns. */ public void setEnabledStatsPatterns(String[] enabledStatsPatterns) { - Assert.notEmpty(enabledStatsPatterns, "componentNamePatterns must not be empty"); + Assert.notEmpty(enabledStatsPatterns, "enabledStatsPatterns must not be empty"); this.enabledStatsPatterns = Arrays.copyOf(enabledStatsPatterns, enabledStatsPatterns.length); } @@ -175,9 +185,12 @@ public class IntegrationManagementConfigurer implements SmartInitializingSinglet Assert.state(this.applicationContext != null, "'applicationContext' must not be null"); Assert.state(MANAGEMENT_CONFIGURER_NAME.equals(this.beanName), getClass().getSimpleName() + " bean name must be " + MANAGEMENT_CONFIGURER_NAME); - if (this.metricsFactoryBeanName != null) { + if (this.metricsFactory == null && StringUtils.hasText(this.metricsFactoryBeanName)) { this.metricsFactory = this.applicationContext.getBean(this.metricsFactoryBeanName, MetricsFactory.class); } + if (this.metricsFactory == null) { + this.metricsFactory = new DefaultMetricsFactory(); + } Map managed = this.applicationContext.getBeansOfType(IntegrationManagement.class); for (Entry entry : managed.entrySet()) { IntegrationManagement bean = entry.getValue(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java index 070e1eb1b0..db23ead97d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java @@ -15,7 +15,9 @@ */ package org.springframework.integration.support.management; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -26,10 +28,18 @@ import java.util.Map; import org.junit.Test; import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.config.EnableIntegrationManagement; import org.springframework.integration.endpoint.AbstractMessageSource; import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.router.RecipientListRouter; +import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.MessageChannel; /** * @author Gary Russell @@ -73,4 +83,28 @@ public class IntegrationManagementConfigurerTests { assertFalse(source.isLoggingEnabled()); } + @Test + public void testEmptyAnnotation() { + AnnotationConfigApplicationContext ctx = + new AnnotationConfigApplicationContext(ConfigEmptyAnnotation.class); + AbstractMessageChannel channel = ctx.getBean("channel", AbstractMessageChannel.class); + assertTrue(channel.isCountsEnabled()); + assertTrue(channel.isStatsEnabled()); + assertThat(TestUtils.getPropertyValue(channel, "channelMetrics"), + instanceOf(DefaultMessageChannelMetrics.class)); + ctx.close(); + } + + @Configuration + @EnableIntegration + @EnableIntegrationManagement + public static class ConfigEmptyAnnotation { + + @Bean + public MessageChannel channel() { + return new DirectChannel(); + } + + } + }