如何配置Spring Integration?

时间:2015-01-23 07:13:03

标签: java spring spring-integration

我有spring-integration-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration" //etc. >

<channel id="inputChannel"/>

<channel id="outputChannel">
    <queue capacity="10"/>
</channel>

<service-activator input-channel="inputChannel"
                   output-channel="outputChannel"
                   ref="gmailWorker"
                   method="getGmailMessage"/>

<beans:bean id="gmailWorker" class="GmailWorker"/>

Configuation:

@Configuration
@ImportResource("classpath:spring-integration-config.xml")
public class PropertiesConfig {
}

和GmailWorker:

public class GmailWorker{
public static Message getGmailMessage(Gmail service,String messageId) throws IOException {
    Message gmailMessage = service.users().messages().get("me", messageId).execute();
    return gmailMessage;
}
}

现在我不使用InputChannel bean。但我的应用程序没有部署在带有日志的tomcat上:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0': 
Cannot resolve reference to bean 'org.springframework.integration.config.ServiceActivatorFactoryBean#0' while setting bean property 'handler'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ServiceActivatorFactoryBean#0':
FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: 
Target object of type [class GmailWorker] has no eligible methods for handling Messages.

如何配置Spring Integration?如何在应用程序中使用inputChannel

1 个答案:

答案 0 :(得分:1)

对于Spring Integration运行时方法调用引擎,您的POJO方法看起来很糟糕。

任何Spring Integration组件都会处理Message对象,该对象具有headerspayload属性。

当它调用POJO方法时,它需要在方法上设置一些受限制的参数:

  • 整个Message
  • 任何其他可被视为payload的类型,如果此问题有适当的converter
  • @Header作为MessageHeaders
  • 中某些标头的请求
  • Map<String, Object> as whole set of MessageHeaders`
  • 如果您想与payload和某些标题进行交易,可以使用@Payload@Headers等标记参数。

更多信息是here