INT-2417 Alias Endpoints with Generated Names
Handlers for consumer endpoints get a generated name derived from the endpoint class name. It is useful (for example for autowiring in tests) to give the handlers a well-known name. If the endpoint has an ID attribute, the handler now gets a bean name of "<ID>.handler".
This commit is contained in:
@@ -40,6 +40,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
@@ -88,7 +89,8 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class);
|
||||
|
||||
String handlerBeanName = BeanDefinitionReaderUtils.generateBeanName(handlerBeanDefinition, parserContext.getRegistry());
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerBeanDefinition, handlerBeanName));
|
||||
String[] handlerAlias = IntegrationNamespaceUtils.generateAlias(element);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerBeanDefinition, handlerBeanName, handlerAlias));
|
||||
|
||||
builder.addPropertyReference("handler", handlerBeanName);
|
||||
String inputChannelName = element.getAttribute(inputChannelAttributeName);
|
||||
|
||||
@@ -76,7 +76,8 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann
|
||||
definition.getPropertyValues().addPropertyValue(IntegrationNamespaceUtils.ORDER, order);
|
||||
}
|
||||
String beanName = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry());
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(definition, beanName));
|
||||
String[] handlerAlias = IntegrationNamespaceUtils.generateAlias(element);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(definition, beanName, handlerAlias));
|
||||
return beanName;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.ID_ATTRIBUTE;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -45,6 +47,8 @@ public abstract class IntegrationNamespaceUtils {
|
||||
static final String METHOD_ATTRIBUTE = "method";
|
||||
static final String ORDER = "order";
|
||||
static final String EXPRESSION_ATTRIBUTE = "expression";
|
||||
public static final String HANDLER_ALIAS_SUFFIX = ".handler";
|
||||
|
||||
|
||||
/**
|
||||
* Configures the provided bean definition builder with a property value corresponding to the attribute whose name
|
||||
@@ -254,4 +258,13 @@ public abstract class IntegrationNamespaceUtils {
|
||||
rootBuilder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] generateAlias(Element element) {
|
||||
String[] handlerAlias = null;
|
||||
String id = element.getAttribute(ID_ATTRIBUTE);
|
||||
if (StringUtils.hasText(id)) {
|
||||
handlerAlias = new String[] {id + HANDLER_ALIAS_SUFFIX};
|
||||
}
|
||||
return handlerAlias;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user