配置问题:无法为 XML 架构命名空间 [http://www.springframework.org/schema/data/mongo] 找到 Spring NamespaceHandler

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/data/mongo]

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

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

我收到以下错误:

线程 "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException 中的异常:配置问题:无法找到 XML 架构名称空间 [Spring 的 Spring NamespaceHandler [http://www.springframework.org/schema/data/mongo] 违规资源:class路径资源[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 集成在一起,我可以参考?

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

为了使用 XML 骆驼配置

<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>