是否可以在camelContext中同时使用routeContextRef和dataFormats元素?

时间:2013-05-24 12:43:52

标签: apache-camel

当我尝试这样做时,我得到:

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 35 in XML document from class path resource [META-INF/spring/camel-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 55; cvc-complex-type.2.4.a: Invalid content was found starting with element 'routeContextRef'. One of '{"http://camel.apache.org/schema/spring":redeliveryPolicyProfile, "http://camel.apache.org/schema/spring":onException, "http://camel.apache.org/schema/spring":onCompletion, "http://camel.apache.org/schema/spring":intercept, "http://camel.apache.org/schema/spring":interceptFrom, "http://camel.apache.org/schema/spring":interceptSendToEndpoint, "http://camel.apache.org/schema/spring":route}' is expected.

检查模式,显然无法在routeContext中定义可以使用dataFormat的路由,因为dataFormats元素必须遵循routeContextRef元素。

我是否需要放弃routeContext组织方法并将所有路由放在一个文件中?

这是驼峰语境的略微划分的版本。我需要能够在cContext中使用json。

<?xml version="1.0" ?>
<beans
   xmlns="http://www.springframework.org/schema/beans"  
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
 http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616"/>
        </bean>
    </property>
</bean>

<import resource="classBeanDefs.xml"/>
<import resource="a.xml"/>
<import resource="b.xml"/>
<import resource="c.xml"/>

<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder id="properties"
                         location="classpath:route.properties"
                         xmlns="http://camel.apache.org/schema/spring"/>

    <dataFormats>
        <json id="json" library="Jackson"/>
    </dataFormats>

    <routeContextRef ref="aContext"/>
    <routeContextRef ref="bContext"/>
    <routeContextRef ref="cContext"/>
</camelContext>

</beans>

当我尝试将dataFormats元素添加到routeContext时,我得到了类似的错误,架构明显不赞同。

1 个答案:

答案 0 :(得分:4)

你应该在 dataFormats之前有你的routeContextRef