0

現在、mongodb を春のアプリケーションに統合しようとしています。

マシン、サービスの起動などで初期のmongodb環境をセットアップしています。

ただし、春のアプリケーション構成では、mongoTemplate construction-arg に関連するエラーがあります。

「ワイルドカードは厳密ですが、要素の宣言が見つかりません」

ここのドキュメントで説明されているのと同じ xml 支出を実際に使用しました。これは、オンラインの最近のチュートリアルと同じであり、私が知る限り、正しい名前空間 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>
4

1 に答える 1

1

使用している spring バージョンと一致するように 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">
于 2016-11-20T15:52:17.250 に答える