2016-11-20 7 views
0

現在、私のSpringアプリケーションへのmongodbの統合を試みています。SpringDataとMongoDBの設定エラー:MongoTemplate

私は

「ワイルドカードmongoTemplate建設、引数に関連したエラーがある春にアプリケーションの構成上しかしなど私のマシン上の初期のMongoDB環境のセットアップ、サービスの起動、

を持っています厳密ではありませんが、文書hereで説明したように、私は実際には同じXML支出を使用していた要素が見つかりませ宣言」

、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

どのバージョンのspring-dataとspring-data-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

これはトリックです。なぜこれが事件か春なのかについての説明は不安定ですか?Veeramありがとう! – Catresl

+0

はい、consturctor-argのname属性は春3以降にしか利用できません。したがって、xsdsを修飾しないと、springはname属性が利用できなかったときに以前のバージョンに解決します。 – Veeram

+0

非常にいいです。私は物事の壮大な計画で春に新しいです。ありがとうございました。 – Catresl

関連する問題