在骆驼上下文中添加时jmxagent抛出saxparse异常

时间:2019-05-08 10:53:19

标签: java jboss xsd apache-camel xsd-validation

我在camelcontext.xml中添加了以下代码段

<jmxAgent id="agent" createConnector="true" />

但是在Jboss实例中部署它时,上面添加的代码给了我以下异常:

------------------

>  nested exception is
> org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
> Line 64 in XML document from class path resource
> [META-INF/spring/camel-routes/camel-context.xml] is invalid; nested
> exception is org.xml.sax.SAXParseException; lineNumber: 64;
> columnNumber: 49; cvc-complex-type.2.4.a: Invalid content was found
> starting with element 'jmxAgent'. One of
> '{"http://camel.apache.org/schema/spring":threadPoolProfile,
> "http://camel.apache.org/schema/spring":threadPool,
> "http://camel.apache.org/schema/spring":endpoint,
> "http://camel.apache.org/schema/spring":dataFormats,
> "http://camel.apache.org/schema/spring":transformers,
> "http://camel.apache.org/schema/spring":validators,
> "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":restConfiguration,
> "http://camel.apache.org/schema/spring":rest,
> "http://camel.apache.org/schema/spring":route}' is expected.
>         at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
> [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
>         at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
> [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
>         at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
> [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]

以下是我完整的camelcontext.xml:

  <?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"
          xmlns:context="http://www.springframework.org/schema/context"
            xmlns:util="http://www.springframework.org/schema/util"
         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   
                http://www.springframework.org/schema/util     
                http://www.springframework.org/schema/util/spring-util-3.0.xsd
               http://www.springframework.org/schema/context  
               http://www.springframework.org/schema/context/spring-context.xsd ">

    <context:annotation-config />
    <import resource="file:${FIS_HOME}/CONFIG/database-context.xml" />
    <import resource="file:${FIS_HOME}/Scheduler/job-scheduer.xml" />
    <import resource="file:${FIS_HOME}/Process/processor-context.xml" />
    <!-- End : Files import to camel context-->
    <camelContext xmlns="http://camel.apache.org/schema/spring" 
 trace="true" streamCache="true" lazyLoadTypeConverters="true" id="main">
        <properties>
<property key="CamelLogEipName" value="com.mycode.route"/>
        </properties>

<propertyPlaceholder id="properties" location="file:${FIS_HOME}/Config/routes.properties"                            xmlns="http://camel.apache.org/schema/spring"/>

 <routeContextRef ref="manager-job-routes" />
<routeContextRef ref="report-routes" />

<threadPoolProfile id="DefaultThreadPoolProfile" defaultProfile="true"
poolSize="70" maxPoolSize="100" maxQueueSize="-1" allowCoreThreadTimeOut="false" rejectedPolicy="CallerRuns"/>

 <jmxAgent id="agent" createConnector="true" statisticsLevel="RoutesOnly"/>

</camelContext>
</beans>`

我使用的骆驼的版本是2.23.2。我也对骆驼有以下依赖性:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jmx</artifactId>
        <version>${camel.version}</version>
    </dependency>`

我更改了骆驼弹簧xsds,但问题仍然存在

1 个答案:

答案 0 :(得分:0)

我认为问题在于jmxAgent标签的顺序。将jmxAgent标记放在camelContext标记的开头。检查camel-spring.xsd,您会发现

  <xs:extension base="tns:abstractCamelContextFactoryBean">
    <xs:sequence>
      ....
      <xs:element minOccurs="0" ref="tns:packageScan"/>
      <xs:element minOccurs="0" ref="tns:contextScan"/>
      <xs:element minOccurs="0" ref="tns:streamCaching"/>
      <xs:element minOccurs="0" ref="tns:jmxAgent"/>
      .....
      <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:routeContextRef"/>
      <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:restContextRef"/>
      <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:threadPoolProfile"/>
      <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:threadPool"/>
      <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:endpoint"/>
      .....
   </xs:sequence>
  </xs:extension>