Spring Boot Apache Camel(Red Hat Fuse)应用程序为 xml 定义的路由抛出异常:javax.xml.bind.UnmarshalException:意外元素

相互依存

我有一个 Spring Boot Apache Camel 应用程序,我在其中定义了一些 XML 路由,这是一个简化的代码:

摇篮配置:

buildscript {
    ext {
        springBootVersion = '1.5.14.RELEASE'
    }
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

apply plugin: 'org.springframework.boot'

description = """myfuse"""

ext {
    junitVersion = '5.2.0'
    junitPlatformVersion = '1.2.0'
    fabric8Version = '3.0.11.fuse-000065-redhat-3'
}

dependencyManagement {
    imports {
        mavenBom "io.fabric8:fabric8-project-bom-camel-spring-boot:${fabric8Version}"
    }
}

dependencies {
    compile 'org.apache.camel:camel-spring-boot-starter',
            "org.springframework.boot:spring-boot-starter-web",
            "org.springframework.boot:spring-boot-starter-actuator"
    testCompile 'es.mma.architecture:mma-arch-test',
            "org.springframework.boot:spring-boot-starter-test",
            'com.github.sbrannen:spring-test-junit5:1.0.2',
            "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
    testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}",
            "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}

骆驼/骆驼-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       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">
    <camel:camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        <route id="_route1">
            <from uri="timer://fooXml?delay={{timer.xml.delay}}&amp;period={{timer.xml.period}}"/>
            <setBody>
                <simple>foo XML message</simple>
            </setBody>
            <log message="${body}"/>
            <to uri="log:fooXmlLog"/>
        </route>
    </camel:camelContext>
</beans>

根据文档,我将 camel-context.xml 放在名为camel.

当应用程序启动时,它抛出以下异常(尽管在 xml 命名空间中定义了 beans 元素,但它无法识别):

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.springframework.org/schema/beans", local:"beans"). Expected elements are <{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}asn1>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}barcode>,<{http://camel.apache.org/schema/spring}base64>,<{http://camel.apache.org/schema/spring}batch-config>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanPostProcessor>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}blacklistServiceFilter>,<{http://camel.apache.org/schema/spring}boon>,<{http://camel.apache.org/schema/spring}cachingServiceDiscovery>,<{http://camel.apache.org/schema/spring}camelContext>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}circuitBreaker>,<{http://camel.apache.org/schema/spring}claimCheck>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}consulServiceDiscovery>,<{http://camel.apache.org/schema/spring}consumerTemplate>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}customServiceFilter>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}defaultLoadBalancer>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}delete>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}dnsServiceDiscovery>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{http://camel.apache.org/schema/spring}doTry>,<{http://camel.apache.org/schema/spring}dynamicRouter>,<{http://camel.apache.org/schema/spring}el>,<{http://camel.apache.org/schema/spring}endpoint>,<{http://camel.apache.org/schema/spring}enrich>,<{http://camel.apache.org/schema/spring}errorHandler>,<{http://camel.apache.org/schema/spring}etcdServiceDiscovery>,<{http://camel.apache.org/schema/spring}exchangeProperty>,<{http://camel.apache.org/schema/spring}export>,<{http://camel.apache.org/schema/spring}expression>,<{http://camel.apache.org/schema/spring}expressionDefinition>,<{http://camel.apache.org/schema/spring}failover>,<{http://camel.apache.org/schema/spring}fhirJson>,<{http://camel.apache.org/schema/spring}fhirXml>,<{http://camel.apache.org/schema/spring}filter>,<{http://camel.apache.org/schema/spring}flatpack>,<{http://camel.apache.org/schema/spring}fluentTemplate>,<{http://camel.apache.org/schema/spring}from>,<{http://camel.apache.org/schema/spring}get>,<{http://camel.apache.org/schema/spring}globalOption>,<{http://camel.apache.org/schema/spring}globalOptions>,<{http://camel.apache.org/schema/spring}groovy>,<{http://camel.apache.org/schema/spring}gzip>,<{http://camel.apache.org/schema/spring}head>,<{http://camel.apache.org/schema/spring}header>,<{http://camel.apache.org/schema/spring}healthyServiceFilter>,<{http://camel.apache.org/schema/spring}hessian>,<{http://camel.apache.org/schema/spring}hl7>,<{http://camel.apache.org/schema/spring}hystrix>,<{http://camel.apache.org/schema/spring}hystrixConfiguration>,<{http://camel.apache.org/schema/spring}ical>,<{http://camel.apache.org/schema/spring}idempotentConsumer>,<{http://camel.apache.org/schema/spring}inOnly>,<{http://camel.apache.org/schema/spring}inOut>,<{http://camel.apache.org/schema/spring}inputType>,<{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}jacksonxml>,<{http://camel.apache.org/schema/spring}javaScript>,<{http://camel.apache.org/schema/spring}jaxb>,<{http://camel.apache.org/schema/spring}jibx>,<{http://camel.apache.org/schema/spring}jmxAgent>,<{http://camel.apache.org/schema/spring}json>,<{http://camel.apache.org/schema/spring}jsonpath>,<{http://camel.apache.org/schema/spring}jxpath>,<{http://camel.apache.org/schema/spring}keyStoreParameters>,<{http://camel.apache.org/schema/spring}kubernetesServiceDiscovery>,<{http://camel.apache.org/schema/spring}language>,<{http://camel.apache.org/schema/spring}loadBalance>,<{http://camel.apache.org/schema/spring}loadBalancerConfiguration>,<{http://camel.apache.org/schema/spring}log>,<{http://camel.apache.org/schema/spring}loop>,<{http://camel.apache.org/schema/spring}lzf>,<{http://camel.apache.org/schema/spring}marshal>,<{http://camel.apache.org/schema/spring}method>,<{http://camel.apache.org/schema/spring}mime-multipart>,<{http://camel.apache.org/schema/spring}multiServiceDiscovery>,<{http://camel.apache.org/schema/spring}multiServiceFilter>,<{http://camel.apache.org/schema/spring}multicast>,<{http://camel.apache.org/schema/spring}mvel>,<{http://camel.apache.org/schema/spring}ognl>,<{http://camel.apache.org/schema/spring}onCompletion>,<{http://camel.apache.org/schema/spring}onException>,<{http://camel.apache.org/schema/spring}onFallback>,<{http://camel.apache.org/schema/spring}optimisticLockRetryPolicy>,<{http://camel.apache.org/schema/spring}options>,<{http://camel.apache.org/schema/spring}otherwise>,<{http://camel.apache.org/schema/spring}outputType>,<{http://camel.apache.org/schema/spring}packageScan>,<{http://camel.apache.org/schema/spring}param>,<{http://camel.apache.org/schema/spring}passThroughServiceFilter>,<{http://camel.apache.org/schema/spring}patch>,<{http://camel.apache.org/schema/spring}pgp>,<{http://camel.apache.org/schema/spring}php>,<{http://camel.apache.org/schema/spring}pipeline>,<{http://camel.apache.org/schema/spring}policy>,<{http://camel.apache.org/schema/spring}pollEnrich>,<{http://camel.apache.org/schema/spring}post>,<{http://camel.apache.org/schema/spring}process>,<{http://camel.apache.org/schema/spring}properties>,<{http://camel.apache.org/schema/spring}propertiesFunction>,<{http://camel.apache.org/schema/spring}propertiesLocation>,<{http://camel.apache.org/schema/spring}property>,<{http://camel.apache.org/schema/spring}propertyPlaceholder>,<{http://camel.apache.org/schema/spring}protobuf>,<{http://camel.apache.org/schema/spring}proxy>,<{http://camel.apache.org/schema/spring}put>,<{http://camel.apache.org/schema/spring}python>,<{http://camel.apache.org/schema/spring}random>,<{http://camel.apache.org/schema/spring}recipientList>,<{http://camel.apache.org/schema/spring}redeliveryPolicy>,<{http://camel.apache.org/schema/spring}redeliveryPolicyProfile>,<{http://camel.apache.org/schema/spring}ref>,<{http://camel.apache.org/schema/spring}removeHeader>,<{http://camel.apache.org/schema/spring}removeHeaders>,<{http://camel.apache.org/schema/spring}removeProperties>,<{http://camel.apache.org/schema/spring}removeProperty>,<{http://camel.apache.org/schema/spring}resequence>,<{http://camel.apache.org/schema/spring}responseHeader>,<{http://camel.apache.org/schema/spring}responseMessage>,<{http://camel.apache.org/schema/spring}rest>,<{http://camel.apache.org/schema/spring}restBinding>,<{http://camel.apache.org/schema/spring}restConfiguration>,<{http://camel.apache.org/schema/spring}restContext>,<{http://camel.apache.org/schema/spring}restContextRef>,<{http://camel.apache.org/schema/spring}restProperty>,<{http://camel.apache.org/schema/spring}rests>,<{http://camel.apache.org/schema/spring}ribbonLoadBalancer>,<{http://camel.apache.org/schema/spring}rollback>,<{http://camel.apache.org/schema/spring}roundRobin>,<{http://camel.apache.org/schema/spring}route>,<{http://camel.apache.org/schema/spring}routeBuilder>,<{http://camel.apache.org/schema/spring}routeContext>,<{http://camel.apache.org/schema/spring}routeContextRef>,<{http://camel.apache.org/schema/spring}routes>,<{http://camel.apache.org/schema/spring}routingSlip>,<{http://camel.apache.org/schema/spring}rss>,<{http://camel.apache.org/schema/spring}ruby>,<{http://camel.apache.org/schema/spring}saga>,<{http://camel.apache.org/schema/spring}sample>,<{http://camel.apache.org/schema/spring}script>,<{http://camel.apache.org/schema/spring}secureRandomParameters>,<{http://camel.apache.org/schema/spring}secureXML>,<{http://camel.apache.org/schema/spring}serialization>,<{http://camel.apache.org/schema/spring}serviceCall>,<{http://camel.apache.org/schema/spring}serviceCallConfiguration>,<{http://camel.apache.org/schema/spring}serviceChooserConfiguration>,<{http://camel.apache.org/schema/spring}serviceDiscoveryConfiguration>,<{http://camel.apache.org/schema/spring}serviceExpression>,<{http://camel.apache.org/schema/spring}serviceFilterConfiguration>,<{http://camel.apache.org/schema/spring}setBody>,<{http://camel.apache.org/schema/spring}setExchangePattern>,<{http://camel.apache.org/schema/spring}setFaultBody>,<{http://camel.apache.org/schema/spring}setHeader>,<{http://camel.apache.org/schema/spring}setOutHeader>,<{http://camel.apache.org/schema/spring}setProperty>,<{http://camel.apache.org/schema/spring}simple>,<{http://camel.apache.org/schema/spring}soapjaxb>,<{http://camel.apache.org/schema/spring}sort>,<{http://camel.apache.org/schema/spring}spel>,<{http://camel.apache.org/schema/spring}split>,<{http://camel.apache.org/schema/spring}sql>,<{http://camel.apache.org/schema/spring}sslContextParameters>,<{http://camel.apache.org/schema/spring}staticServiceDiscovery>,<{http://camel.apache.org/schema/spring}sticky>,<{http://camel.apache.org/schema/spring}stop>,<{http://camel.apache.org/schema/spring}stream-config>,<{http://camel.apache.org/schema/spring}streamCaching>,<{http://camel.apache.org/schema/spring}string>,<{http://camel.apache.org/schema/spring}syslog>,<{http://camel.apache.org/schema/spring}tarfile>,<{http://camel.apache.org/schema/spring}template>,<{http://camel.apache.org/schema/spring}terser>,<{http://camel.apache.org/schema/spring}threadPool>,<{http://camel.apache.org/schema/spring}threadPoolProfile>,<{http://camel.apache.org/schema/spring}threads>,<{http://camel.apache.org/schema/spring}thrift>,<{http://camel.apache.org/schema/spring}throttle>,<{http://camel.apache.org/schema/spring}throwException>,<{http://camel.apache.org/schema/spring}tidyMarkup>,<{http://camel.apache.org/schema/spring}to>,<{http://camel.apache.org/schema/spring}toD>,<{http://camel.apache.org/schema/spring}tokenize>,<{http://camel.apache.org/schema/spring}topic>,<{http://camel.apache.org/schema/spring}transacted>,<{http://camel.apache.org/schema/spring}transform>,<{http://camel.apache.org/schema/spring}transformers>,<{http://camel.apache.org/schema/spring}typeFilter>,<{http://camel.apache.org/schema/spring}univocity-csv>,<{http://camel.apache.org/schema/spring}univocity-fixed>,<{http://camel.apache.org/schema/spring}univocity-header>,<{http://camel.apache.org/schema/spring}univocity-tsv>,<{http://camel.apache.org/schema/spring}unmarshal>,<{http://camel.apache.org/schema/spring}validate>,<{http://camel.apache.org/schema/spring}validators>,<{http://camel.apache.org/schema/spring}verb>,<{http://camel.apache.org/schema/spring}weighted>,<{http://camel.apache.org/schema/spring}when>,<{http://camel.apache.org/schema/spring}wireTap>,<{http://camel.apache.org/schema/spring}xmlBeans>,<{http://camel.apache.org/schema/spring}xmljson>,<{http://camel.apache.org/schema/spring}xmlrpc>,<{http://camel.apache.org/schema/spring}xpath>,<{http://camel.apache.org/schema/spring}xquery>,<{http://camel.apache.org/schema/spring}xstream>,<{http://camel.apache.org/schema/spring}xtokenize>,<{http://camel.apache.org/schema/spring}yaml>,<{http://camel.apache.org/schema/spring}zip>,<{http://camel.apache.org/schema/spring}zipFile>,<{http://camel.apache.org/schema/spring}zookeeperServiceDiscovery>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:743) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:257) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:124) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1148) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:573) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:555) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:168) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244) ~[jaxb-core-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127) ~[jaxb-core-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:110) ~[jaxb-core-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:103) ~[jaxb-core-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:161) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:132) ~[jaxb-impl-2.2.11.redhat-4.jar:2.2.11.redhat-4]
    at org.apache.camel.model.ModelHelper.loadRoutesDefinition(ModelHelper.java:171) ~[camel-core-2.21.0.fuse-000112-redhat-3.jar:2.21.0.fuse-000112-redhat-3]
    at org.apache.camel.model.ModelHelper.loadRoutesDefinition(ModelHelper.java:152) ~[camel-core-2.21.0.fuse-000112-redhat-3.jar:2.21.0.fuse-000112-redhat-3]
    at org.apache.camel.impl.DefaultCamelContext.loadRoutesDefinition(DefaultCamelContext.java:1034) ~[camel-core-2.21.0.fuse-000112-redhat-3.jar:2.21.0.fuse-000112-redhat-3]
    at org.apache.camel.spring.boot.RoutesCollector.loadXmlRoutes(RoutesCollector.java:281) ~[camel-spring-boot-2.21.0.fuse-000112-redhat-3.jar:2.21.0.fuse-000112-redhat-3]
    at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:142) ~[camel-spring-boot-2.21.0.fuse-000112-redhat-3.jar:2.21.0.fuse-000112-redhat-3]
    ... 16 common frames omitted

为什么它不允许使用 beans 元素?

现在有些奇怪:我将 camel-context.xml 文件移动到另一个文件夹:spring/camel-context.xml,并在 Spring Boot Application 上下文中直接导入 XML:

@SpringBootApplication
@ImportResource({"classpath:spring/camel-context.xml"})
public class CamelSpringBootApplication  {

现在它工作正常(???)。

相互依存

我在http://camel.apache.org/spring-boot.html找到了答案

XML 文件应该是 Camel XML 路由(不是 CamelContext)

所以我将路由定义更改为以下内容并解决了问题:

<?xml version="1.0" encoding="UTF-8"?>
<route id="_route1" xmlns="http://camel.apache.org/schema/spring">
    <from uri="timer://fooXml?delay={{timer.xml.delay}}&amp;period={{timer.xml.period}}"/>
    <setBody>
        <simple>foo XML message</simple>
    </setBody>
    <log message="${body}"/>
    <to uri="log:fooXmlLog"/>
</route>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章