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:
Gary Russell
2012-05-17 16:04:07 -04:00
parent b2620122e7
commit 59d7432eef
7 changed files with 55 additions and 14 deletions

View File

@@ -19,11 +19,9 @@ package org.springframework.integration.config.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.config.TestConsumer;
import org.springframework.integration.handler.MethodInvokingMessageHandler;
@@ -34,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -42,6 +41,15 @@ public class DefaultOutboundChannelAdapterParserTests {
@Autowired
private ApplicationContext context;
@SuppressWarnings("unused") // testing auto wiring only
@Autowired
@Qualifier("org.springframework.integration.handler.MethodInvokingMessageHandler#0")
private MethodInvokingMessageHandler adapterByGeneratedName;
@SuppressWarnings("unused") // testing auto wiring only
@Autowired
@Qualifier("adapter.handler")
private MethodInvokingMessageHandler adapterByAlias;
@Test
public void checkConfig() {

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<service-activator input-channel="literalExpressionInput" expression="'foo'"/>
<service-activator id="testAlias" input-channel="literalExpressionInput" expression="'foo'"/>
<service-activator input-channel="beanAsTargetInput" expression="@testBean.caps(payload)"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -22,13 +22,16 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
@ContextConfiguration
@@ -53,6 +56,15 @@ public class ServiceActivatorParserTests {
@Autowired
private MessageChannel multipleArgsFromPayloadInput;
@SuppressWarnings("unused") // testing auto wiring only
@Autowired
@Qualifier("org.springframework.integration.config.ServiceActivatorFactoryBean#0")
private ServiceActivatingHandler testAliasByGeneratedName;
@SuppressWarnings("unused") // testing auto wiring only
@Autowired
@Qualifier("testAlias.handler")
private ServiceActivatingHandler testAlias;
@Test
public void literalExpression() {