运行 使用 Apache Camel 开发的 jar 时,如何修复路由标签中的 SAXParseException?

How to fix SAXParseException in route tag when run jar developed using Apache Camel?

同事们,我有 Camel 上下文文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       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-2.0.0.xsd">

          <bean id="myFilter" class="com.ac.am.CamelComp.CurrentDateFileFilter"/>
    <bean id="xsdProcessor" class="com.ac.am.CamelComp.MessProcessor"/>
    <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz2.CronScheduledRoutePolicy">
        <property name="routeStartTime" value="0 0/5 * ? * 1-6 *" />
    </bean>

    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
          <route id="uploadFromFtp" routePolicyRef="startPolicy">
            <camel:from uri="sftp://
            &amp;throwExceptionOnConnectFailed=true
            &amp;consumer.delay=10000
            &amp;recursive=true"/>
            <camel:to uri="bean:xsdProcessor"/>
            <camel:to uri="file:sftp-inbound"/>
        </route>
    </camel:camelContext>
</beans>

我使用 mvn clean compile assembly:single 编译了 pogramm。 当我 运行 jar 我收到下一个堆栈跟踪:

[32m13:37:27.923[0;39m [34mINFO [0;39m [32m[main][0;39m [36mo.s.b.f.xml.XmlBeanDefinitionReader[0;39m : Loading XML bean definitions from class path resource [camel-context.xml] [32m13:37:28.331[0;39m [31mWARN [0;39m [32m[main][0;39m [36mo.s.c.a.AnnotationConfigApplicationContext[0;39m : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from class path resource [camel-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 66; cvc-complex-type.3.2.2: Attribute 'routePolicyRef' is not allowed to appear in element 'route'. Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from class path resource [camel-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 66; cvc-complex-type.3.2.2: Attribute 'routePolicyRef' is not allowed to appear in element 'route'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) .... at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524) at org.springframework.context.annotation.AnnotationConfigApplicationContext.(AnnotationConfigApplicationContext.java:84) at com.ac.am.AmeFtp.main(AmeFtp.java:32) Caused by: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 66; cvc-complex-type.3.2.2: Attribute 'routePolicyRef' is not allowed to appear in element 'route'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391) ... 16 more

第 23 行是: <route id="uploadFromFtp" routePolicyRef="startPolicy">

你能帮忙修一下吗?谢谢。

更新

camel 已添加到 route,但没有任何变化

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
          <camel:route id="uploadFromFtp" routePolicyRef="startPolicy">
            <camel:from uri="sftp:......
            &amp;throwExceptionOnConnectFailed=true
            &amp;consumer.delay=10000
            &amp;recursive=true"/>
            <camel:to uri="bean:xsdProcessor"/>
            <camel:to uri="file:sftp-inbound"/>
        </camel:route>
    </camel:camelContext>

堆栈:

Caused by: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 72; cvc-complex-type.3.2.2: Attribute 'routePolicyRef' is not allowed to appear in element 'camel:route'.

lineNumber: 24;<camel:camelContext xmlns="http://camel.apache.org/schema/spring">

您的 camel 命名空间 xmlns:camel="http://camel.apache.org/schema/spring" 映射到架构 http://camel.apache.org/schema/spring/camel-spring-2.0.0.xsd 的 2.0.0 版本(通过 xsi:schemaLocation),它还没有定义 routePolicyRef 属性。

看起来这个属性只在 2.1.0

中添加了
...
<xs:attribute name="routePolicyRef" type="xs:string"/> 
...

因此,错误。

您可以尝试更新您的 xsi:schemaLocation 以指向正确版本的架构(2.1.0 或更高版本),假设您使用的是正确的版本框架本身。