2016-11-20 62 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