377.5. 使用 XML 配置
如果要在 Spring XML 文件中配置路由,那么您可以使用 XPath 表达式,如下所示
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:foo="http://example.com/person" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:MyQueue"/> <filter> <xquery>/foo:person[@name='James']</xquery> <to uri="mqseries:SomeOtherQueue"/> </filter> </route> </camelContext> </beans>
请注意,我们如何重复使用命名空间前缀 foo,本例中为 XPath 表达式,以方便基于命名空间的 XQuery 表达式!
当您在 XQuery 表达式中使用功能时,您需要显式类型转换,该转换可通过 @type 属性在 xml 配置中完成:
<xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery>