【问题标题】:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/data/mongo]配置问题:找不到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/data/mongo]
【发布时间】:2020-04-20 01:12:33
【问题描述】:

我有一个 Apache Camel 的 Maven 项目。 源码在这里:https://github.com/GauravBhandari19/myDevCodePUBLIC/tree/master/maven/Mongo

当我尝试运行 Java 时:App.java 文件

我收到以下错误:

线程 "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException 中的异常:配置问题:找不到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/data/mongo] 违规资源:类路径资源[application-context.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:111)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)

谁能帮助我为什么会出现这个错误,或者有人已经将 Camel(3.2.0) 与 Mongo 集成,我可以参考?

【问题讨论】:

    标签: java mongodb apache-camel


    【解决方案1】:

    为了像使用 XML Camel 配置一样

    <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:mongo="http://www.springframework.org/schema/data/mongo"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
              http://camel.apache.org/schema/spring
              http://camel.apache.org/schema/spring/camel-spring.xsd">
    
    
        <mongo:mongo-client id="myDb" host="${mongo.url}" port="${mongo.port}" />
    </beans>  
    

    你需要添加

    
    <repositories>
      <repository>
        <id>spring-milestone</id>
        <name>Spring Maven MILESTONE Repository</name>
        <url>https://repo.spring.io/libs-milestone</url>
      </repository>
    </repositories>
    
    

    到 pom.xml - 更多细节请参考https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference

    骆驼路线示例

     <camelContext id="test" 
                      xmlns="http://camel.apache.org/schema/spring">
            <route autoStartup="true" id="CronQueryMongo">
                <from uri="quartz://test?trigger.repeatInterval=2&amp;trigger.repeatCount=1"/>
                <setHeader name="CamelMongoDbCriteria">
                    <constant>
                        {"_id":1}
                    </constant>
                </setHeader>
                <to uri="mongodb:myDb?database=meteor&amp;collection=msg&amp;operation=findAll"/>
                <transform>
                    <simple>${body.toString()}</simple>
                </transform>
                <to uri="stream:out"/>
            </route>
        </camelContext>
    

    【讨论】:

      【解决方案2】:

      错误是由于 pom.xml 中缺少 depy。我添加了 Camel Mongo 建议条目,我没有遇到这个问题。但是我改变了连接到 Mongo 的方法,我现在将路由连接到类组件并且在使用 Mongo Client 的类中。我的 GITHUB 文件夹上的代码更新。 :)

      【讨论】:

        猜你喜欢
        • 2013-04-16
        • 2019-05-07
        • 2012-02-05
        • 2013-11-06
        • 2015-10-29
        • 1970-01-01
        • 2012-01-21
        • 2013-11-01
        • 2011-11-03
        相关资源
        最近更新 更多