2016-11-20 44 views
0

我目前正在尝试将MongoDB集成到我的Spring应用程序中。SpringData和MongoDB配置错误:MongoTemplate

我最初的MongoDB的环境设置我的机器上,服务启动,等

但是在春天应用配置上有相关的mongoTemplate建筑ARG

“通配符的错误是严格的,但没有发现元素的声明“

我已经使用了相同的xml费用,如文档here中所述,与最近的一些教程相同ne,并且据我所知,我添加了正确的命名空间url。所以我现在有点失落,因为我失踪了。任何对此的帮助是最感激。

这里看看xml配置:

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:beans="http://www.springframework.org/schema/beans" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:mongo="http://www.springframework.org/schema/data/mongo" 
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 




    <!-- scanning comment root context of all components package directory--> 
    <context:component-scan base-package="com.demo" /> 


    <!--Dispatcher servlet--> 
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/view/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 


    <!-- Configure to plugin JSON as request and response in method handler --> 
    <beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> 
     <beans:property name="messageConverters"> 
      <beans:list> 
       <beans:ref bean="jsonMessageConverter"/> 
      </beans:list> 
     </beans:property> 
    </beans:bean> 


    <!-- Configure bean to convert JSON to POJO and vice versa --> 
    <beans:bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 
    </beans:bean> 


    <!-- mongo db config --> 
    <mongo:mongo host="localhost" port="27017" id="mongo" /> 

    <mongo:repositories base-package="com.demo.football.repository" /> 

    <beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> 
     <constructor-arg ref="mongo"/> 
     <constructor-arg name="databaseName" value="FootballManager"/> 
    </beans:bean> 



</beans:beans> 
+0

你使用的是什么版本的spring-data和spring-data-mongodb? – Veeram

+0

spring-mongo-mongodb是版本1.7.2,没有弹簧数据依赖性要求 - 据我所知.. – Catresl

回答

1

资格的XSD名称以匹配您正在使用Spring的版本。

考虑到您使用的是Spring 4,xshema名称空间将更改为以下内容。

<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:beans="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mongo="http://www.springframework.org/schema/data/mongo" 
     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.7.xsd"> 
+0

这已经完成了这个伎俩。任何解释为什么这是事实或春天是挑剔的?谢谢你Veeram! – Catresl

+0

是的,consturctor-arg的name属性只在spring 3之后才可用。所以当你没有限定xsds时,当name属性不可用时,spring将它解析为较早的版本。 – Veeram

+0

非常好。在新的宏伟计划中,我是新的。谢谢。 – Catresl