2016-11-09 22 views
0

我與一個JEE項目,從Maven項目到動態Web。 問題是我沒有使用xml配置,但現在,我必須使用Dynamic web項目。春:Mongo的配置不能找到「蒙戈:庫」

我無法弄清楚如何正確書寫applicationContext.xml中;我讀過很多話題,但沒有人幫助我。

這裏的代碼和錯誤:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:sec="http://www.springframework.org/schema/security" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:util="http://www.springframework.org/schema/util" 
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:mongo="http://www.springframework.org/schema/data/mong‌​o" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.2.xsd  
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-4.2.xsd 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee-4.2.xsd 
    http://www.springframework.org/schema/data/mongo 
    http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"> 

    <!-- Abilita l'uso di tutte le annotazioni --> 
    <context:annotation-config/> 
    <import resource="security-config.xml"/> 

    <context:component-scan base-package="it.**"/> 

    <!-- Abilita il supporto AOP --> 
    <aop:aspectj-autoproxy proxy-target-class="true"/> 
    <util:properties id="settings" location="classpath:../../META-INF/MANIFEST.MF"/> 

    <!-- i valori delle properties vengono iniettati in AuthentificationFilter e il id=myProps serve per l'iniezione --> 
    <util:properties id="myProps" location="classpath:muru/application.properties"/> 

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
<property name="locations"> 
    <list> 
    <value>classpath*:muru/*.properties</value> 
    </list> 
</property> 
    <property name="ignoreUnresolvablePlaceholders" value="true"/> 
</bean> 
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> 
    <constructor-arg> 
    <bean class="com.mongodb.MongoClient"> 
    <constructor-arg value="localhost"/> 
    <constructor-arg value="27017"/> 
    </bean> 
    </constructor-arg> 
    <constructor-arg value="database"/> 
</bean> 
<mongo:repositories base-package="it.cap.domain" mongo-template-ref="mongoTemplate"></mongo:repositories> 
    <!-- Abilita la configurazione delle transazioni tramite annotazioni --> 
    <tx:annotation-driven transaction-manager="txManager"/> 
    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> 
    </beans> 

堆棧跟蹤

11:12:26.108 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 68 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 68; columnNumber: 93; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mongo:repositories'. 
at      org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) 

at java.lang.Thread.run(Thread.java:745) 
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mongo:repositories'. 

你能幫助我理解? 感謝諮詢:)

+0

以及錯誤說,你在架構聲明錯誤,所以你必須要有無論是在相同的版本架構聲明或全部刪除的版本,然後Maven的更新,然後嘗試建立 – emotionlessbananas

+0

是在你的包'* .domain'任何庫? – smsnheck

+0

@smsnheck是的。 對於FlyingZombie,我會嘗試刪除版本,反正我從菜單不是「Maven的更新」(右鍵) – bigghe

回答

0

這個問題似乎是從你的背景文件中的bean定義的順序。

剛剛嘗試改變下面bean定義

<tx:annotation-driven transaction-manager="txManager"/> 

的位置從currrent位置就在下面豆後。

<context:component-scan base-package="it.**"/> 

喜歡的東西

<context:component-scan base-package="it.**"/> 
<tx:annotation-driven transaction-manager="txManager"/> 

看看是否能解決您的問題。

供您參考.. http://forum.spring.io/forum/spring-projects/container/9895-order-of-bean-definitions-matters

如果上述解決方案不工作,我想最後一件事是檢查是否正確罐子持有根據您的應用程序的lib文件夾指定蒙戈相關的XSD

+0

我不知道如果'xml'是依賴於訂單 – emotionlessbananas

+0

PLZ檢查引用鏈接.. – mhasan

+0

是它的說法*依賴的bean必須首先被初始化*但是我不確定這與如果'depends-on'沒有被聲明的問題有任何關係,那麼它並不重要,我真的很想知道它是如何結束的:) – emotionlessbananas

0

我發現了一個解決方案,在applicationContext.xml中我只是把一個進口標籤資源「spring.xml」:

<import resource="spring.xml" /> 

而且裏面spring.xml

<!-- MongoDB host --> 
<mongo:mongo host="localhost" port="27017" /> 

<!-- Template for performing MongoDB operations --> 
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" c:mongo-ref="mongo" c:databaseName="dbname" /> 

<!-- Activate Spring Data MongoDB repository support --> 
<mongo:repositories base-package="it.domain" mongo-template-ref="mongoTemplate" /> 

<!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --> 
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 

現在啓動時沒有tomcat的碰撞;我會讓你知道,如果它與db連接正常工作。