78.3. 使用 Spring XML
以下示例演示了如何配置 JaxbDataFormat
,并在多个路由中使用它。
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> <bean id="myJaxb" class="org.apache.camel.converter.jaxb.JaxbDataFormat"> <property name="contextPath" value="org.apache.camel.example"/> </bean> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <marshal><custom ref="myJaxb"/></marshal> <to uri="direct:marshalled"/> </route> <route> <from uri="direct:marshalled"/> <unmarshal><custom ref="myJaxb"/></unmarshal> <to uri="mock:result"/> </route> </camelContext> </beans>
多个上下文路径
可以将这些数据格式与多个上下文路径一起使用。您可以使用 :
作为分隔符来指定上下文路径,例如 com.mycompany:com.mycompany2
。请注意,这由 JAXB 实施处理,如果您使用不同于 RI 的供应商,可能会改变。