1
我正在繼續學習SI,並且正在嘗試構建一個應用程序。彈簧集成 - 錯誤處理的流程
我的申請流程是這樣的:
- 讀取XML文件,並分割每個標籤
- 每個標籤具有定義一個名爲「間隔」的屬性,我需要創建一個將重複的工作,根據這個值。
- 當作業的執行被終止,需要調用Web服務來存儲信息
- 如果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在輪詢器上發生錯誤通道並移除鏈以處理錯誤
我已經修復了這個ref,並按照你的建議給了一個id給鏈。現在程序編譯,但我的例外沒有捕獲(程序「崩潰」)。爲了編寫這段代碼,我使用了github intermedie/errorhandling中提供的示例。你能告訴我如何向輪詢者添加錯誤通道嗎?我爲你寫的流程是好的,或者我做錯了什麼...? – Mistre83
您需要使用當前配置編輯您的問題。 ' '。 –
我已經更新了這個問題,現在似乎工作。當我引發異常時,這是從Resubmitter處理的,它是由服務激活器連接到failedInvocationChannel – Mistre83