2016-02-05 89 views
1

我正在继续学习SI,并且正在尝试构建一个应用程序。弹簧集成 - 错误处理的流程

我的申请流程是这样的:

  1. 读取XML文件,并分割每个标签
  2. 每个标签具有定义一个名为“间隔”的属性,我需要创建一个将重复的工作,根据这个值。
  3. 当作业的执行被终止,需要调用Web服务来存储信息
  4. 如果WBS invokation失败,请通过电子邮件发送信息

现在我到达一个点( :D)这个流程,现在我试图前进,并首先检查错误处理(流程的第4点)。

这是实际的配置,我有这个工作正常分裂的标签,然后调用正确的service-activator

<context:component-scan base-package="it.mypkg" /> 

<si:poller id="poller" default="true" fixed-delay="1000"/> 

<si:channel id="rootChannel" /> 

<si-xml:xpath-splitter id="mySplitter" input-channel="rootChannel" output-channel="routerChannel" create-documents="true"> 
    <si-xml:xpath-expression expression="//service" /> 
</si-xml:xpath-splitter> 

<si-xml:xpath-router id="router" input-channel="routerChannel" evaluate-as-string="true"> 
    <si-xml:xpath-expression expression="concat(name(./node()), 'Channel')" /> 
</si-xml:xpath-router> 

<si:service-activator input-channel="serviceChannel" output-channel="endChannel"> 
    <bean class="it.mypkg.Service" /> 
</si:service-activator> 

的endChannel需要接收来自几个频道的所有消息(路由器发送),然后调用WBS。 现在我正在创建类来检查流是否有效。

我applicationContext.xml中的其余部分是这样的:

<!-- Create a poller that will be used by endChannel --> 
<si:poller id="poller" default="true" fixed-delay="1000" error-channel="failedInvocationChannel" /> 

<!--- take messages from serviceChannel and redirect to endChannel, that is responsable to receive messages from all channels created by the router --> 
<si:service-activator input-channel="serviceChannel" output-channel="endChannel"> 
    <bean class="it.mypkg.Service" /> 
</si:service-activator> 

<!-- end channel is a queue --> 
<si:channel id="endChannel"> 
    <si:queue capacity="10"/> 
</si:channel> 

<!-- Messages are taken from the queue.. --> 
<si:service-activator input-channel="endChannel"> 
    <bean class="it.mypkg.Invokator" /> 
</si:service-activator> 

<!-- Service activator that handle the errors on the queue --> 
<si:channel id="failedInvocationChannel" /> 

<si:service-activator input-channel="failedInvocationChannel"> 
    <bean class="it.mypkg.Resubmitter" /> 
</si:service-activator> 

但是当我运行我的应用程序,我得到这个错误:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#0': Cannot create inner bean 'org.springframework.integration.handler.MessageHandlerChain#0$child#1.handler' of type [org.springframework.integration.config.ServiceActivatorFactoryBean] while setting bean property 'handlers' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#0$child#1.handler': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Target object of type [class org.springframework.integration.channel.QueueChannel] has no eligible methods for handling Messages. 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158) 

我读了很多,我”有点混淆了所有可以使用的组件...也许我的错误是因为我试图以错误的方式使用组件...

编辑:配置更新w ith在轮询器上发生错误通道并移除链以处理错误

回答

1
<si:service-activator ref="endChannel" method="dispatch" /> 

您不能在服务激活器中使用ref通道。

此外,最好给链像id这样的元素,因此异常更容易调试。

此外,您通常不应该操纵errorChannel标题;最好将一个error-channel添加到轮询器并按照这种方式发送错误流。

+0

我已经修复了这个ref,并按照你的建议给了一个id给链。现在程序编译,但我的例外没有捕获(程序“崩溃”)。为了编写这段代码,我使用了github intermedie/errorhandling中提供的示例。你能告诉我如何向轮询者添加错误通道吗?我为你写的流程是好的,或者我做错了什么...? – Mistre83

+0

您需要使用当前配置编辑您的问题。 ''。 –

+0

我已经更新了这个问题,现在似乎工作。当我引发异常时,这是从Resubmitter处理的,它是由服务激活器连接到failedInvocationChannel – Mistre83