INT-568
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ConsumerEndpointFactoryBean implements FactoryBean, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationListener {
|
||||
|
||||
private final MessageHandler handler;
|
||||
private volatile MessageHandler handler;
|
||||
|
||||
private volatile String beanName;
|
||||
|
||||
@@ -58,10 +58,15 @@ public class ConsumerEndpointFactoryBean implements FactoryBean, BeanFactoryAwar
|
||||
|
||||
private final Object initializationMonitor = new Object();
|
||||
|
||||
private final Object handlerMonitor = new Object();
|
||||
|
||||
public ConsumerEndpointFactoryBean(MessageHandler handler) {
|
||||
|
||||
public void setHandler(MessageHandler handler) {
|
||||
Assert.notNull(handler, "handler must not be null");
|
||||
this.handler = handler;
|
||||
synchronized (this.handlerMonitor) {
|
||||
Assert.isNull(this.handler, "handler cannot be overridden");
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -73,7 +73,7 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.ConsumerEndpointFactoryBean");
|
||||
String handlerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(handlerBeanDefinition, parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(handlerBeanName);
|
||||
builder.addPropertyReference("handler", handlerBeanName);
|
||||
String inputChannelName = element.getAttribute(inputChannelAttributeName);
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)) {
|
||||
BeanDefinitionBuilder channelDef = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -37,7 +37,7 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann
|
||||
Element pollerElement = DomUtils.getChildElementByTagName(element, "poller");
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.ConsumerEndpointFactoryBean");
|
||||
builder.addConstructorArgReference(this.parseAndRegisterConsumer(element, parserContext));
|
||||
builder.addPropertyReference("handler", this.parseAndRegisterConsumer(element, parserContext));
|
||||
if (pollerElement != null) {
|
||||
if (!StringUtils.hasText(channelName)) {
|
||||
parserContext.getReaderContext().error(
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<b:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:b="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:annotation-config />
|
||||
|
||||
<channel id="input" />
|
||||
<channel id="output" />
|
||||
|
||||
<b:bean id="service" class="org.springframework.integration.config.xml.ConstructorAutowireTest$TestService" />
|
||||
<b:bean id="endpoint" class="org.springframework.integration.config.xml.ConstructorAutowireTest$TestEndpoint" />
|
||||
|
||||
<inbound-channel-adapter ref="endpoint" method="aProducer" channel="input">
|
||||
<poller max-messages-per-poll="1">
|
||||
<interval-trigger interval="300" time-unit="SECONDS" />
|
||||
</poller>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<splitter input-channel="input" output-channel="output" ref="endpoint" method="aSplitter" />
|
||||
|
||||
<service-activator input-channel="output" ref="endpoint" method="aConsumer"/>
|
||||
|
||||
</b:beans>
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Jim Moore
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConstructorAutowireTest {
|
||||
|
||||
@Test // INT-568
|
||||
public void testApplicationContextCreation() {
|
||||
new ClassPathXmlApplicationContext("ConstructorAutowireTest-context.xml", ConstructorAutowireTest.class);
|
||||
}
|
||||
|
||||
|
||||
public static class TestService {
|
||||
public String getVal() {
|
||||
return "fooble";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class TestEndpoint {
|
||||
|
||||
private TestService service;
|
||||
|
||||
@Autowired
|
||||
public TestEndpoint(TestService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String aProducer() {
|
||||
return this.service.getVal();
|
||||
}
|
||||
|
||||
public void aConsumer(String str) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
public List<String> aSplitter(List<String> strs) {
|
||||
return strs;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user