From fc0af2fed61f32a0d099973bf4f340e115740c71 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Sat, 21 Nov 2015 13:02:50 -0500 Subject: [PATCH] INT-3896: JMX: Fix Double Router MBean Export JIRA: https://jira.spring.io/browse/INT-3896 Routers created by the `RouterFactoryBean` were not suppressed from being exported by the context exporter when an `IMBE` is present. Move the suppression logic to `postProcessAfterInitialization()` so the annotation on the bean created by the factory bean is detected. The annotation is not detected on the factory bean itself in `postProcessBeforeInitialization()`. --- .../integration/jmx/config/MBeanExporterHelper.java | 10 +++++----- .../integration/jmx/config/RouterMBeanTests.java | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java index 6e30de14f1..2ba7f7f697 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java @@ -62,6 +62,11 @@ class MBeanExporterHelper implements BeanPostProcessor, Ordered { } } + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (AnnotatedElementUtils.isAnnotated(AopUtils.getTargetClass(bean), IntegrationManagedResource.class.getName())) { this.siBeanNames.add(beanName); @@ -83,11 +88,6 @@ class MBeanExporterHelper implements BeanPostProcessor, Ordered { return bean; } - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - @Override public int getOrder() { return Ordered.HIGHEST_PRECEDENCE; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java index 7dfceccce4..c49e5f66cb 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2015 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. You may obtain a copy of the License at @@ -90,6 +90,9 @@ public class RouterMBeanTests { // System.err.println(server.queryNames(new ObjectName("*:type=MessageHandler,*"), null)); Set names = server.queryNames(new ObjectName("test.RouterMBean:type=MessageHandler,name=ptRouter,*"), null); assertEquals(1, names.size()); + // INT-3896 + names = server.queryNames(new ObjectName("test.RouterMBean:type=ExpressionEvaluatingRouter,*"), null); + assertEquals(0, names.size()); } public static interface Service {