Spring5升级后Spring Integration配置报错:int:filter属性及子元素异常
Spring 5升级中Spring Integration配置错误修复
原配置代码
<int:filter id="xpathfilter" input-channel="eventSpringXpathChannel" output-channel="eventSpringOutChannel" discard-channel="eventSpringFailureChannel" expression="#xpath(payload, headers.get('xpathKey'), 'boolean')"> <int:request-handler-advice-chain> <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"> <property name="onFailureExpressionString" value="payload" /> <property name="failureChannel" ref="eventSpringXpathErrorChannel" /> <property name="trapException" value="true" /> </bean> </int:request-handler-advice-chain> </int:filter>
错误信息(翻译后)
- cvc-complex-type.3.2.2: 元素'int:filter'中不允许出现属性'expression'
- 无效元素名称:
- request-handler-advice-chain
预期为以下元素之一: - bean
- poller
修复方案
针对错误1调整表达式配置
Spring Integration 5.x中,<int:filter>不再支持直接配置expression属性,需要将过滤表达式移至<int:expression>子元素中定义。
针对错误2调整增强链配置
<int:request-handler-advice-chain>已不是<int:filter>的合法子元素,需替换为<int:advice-chain>来配置处理器增强逻辑。
修复后完整配置
<int:filter id="xpathfilter" input-channel="eventSpringXpathChannel" output-channel="eventSpringOutChannel" discard-channel="eventSpringFailureChannel"> <int:expression>#xpath(payload, headers.get('xpathKey'), 'boolean')</int:expression> <int:advice-chain> <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"> <property name="onFailureExpressionString" value="payload" /> <property name="failureChannel" ref="eventSpringXpathErrorChannel" /> <property name="trapException" value="true" /> </bean> </int:advice-chain> </int:filter>
补充说明
确保配置文件头部的Spring Integration命名空间引用已升级至Spring 5对应的版本:
xmlns:int="http://www.springframework.org/schema/integration" xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd"
内容的提问来源于stack exchange,提问作者VKR
相关产品推荐
相关产品推荐

