63.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>
<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 不同的供应商,可能会改变。