2016-11-20 2 views
0

В настоящее время я пытаюсь интегрировать mongodb в мое приложение весны.Ошибка конфигурации SpringData и MongoDB: MongoTemplate

У меня есть начальная настройка MongoDB среды на моей машине, запуска службы и т.д.

Однако на конфигурации приложения весной происходит ошибка, связанная с mongoTemplate строительства-Arg

«подстановочные строго, но никакое объявления не найдено для элемента»

Я на самом деле использовал те же XML затраты, как описан в документах here, так же как некоторые последние учебники ONLI 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

какая версия весенних данных и данных весны-mongodb вы используете? – Veeram

+0

spring-mongo-mongodb - версия 1.7.2, нет никакой зависимости от весенних данных - насколько мне известно. – Catresl

ответ

1

Квалифицируйтесь имена XSD, чтобы соответствовать версии пружины, которую вы используете.

Учитывая, что вы используете 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

Это сделало трюк. Любое объяснение, почему это так, или весна, является разборчивым? Спасибо, Верам! – Catresl

+0

Да, атрибут name для consturctor-arg доступен только после весны 3. Поэтому, когда вы не квалифицируете xsds, весна разрешает его до более ранней версии, когда атрибут name недоступен. – Veeram

+0

очень приятно. я новичок в весенней схеме вещей. Спасибо. – Catresl