【发布时间】:2016-04-02 08:36:35
【问题描述】:
我的应用程序在启动时崩溃并出现错误:
原因:org.xml.sax.SAXParseException;行号:13;列号:60; cvc-complex-type.2.4.c:匹配的通配符是严格的,但是找不到元素'mongo:mongo'的声明。
我的 context.xml 看起来像这样:
xsi:schemaLocation="
http##://www.springframework.org/schema/beans
http##://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http##://www.springframework.org/schema/data/mongo
http##://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<mongo:mongo id="mongo" host="localhost" port="27017"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="ProcessOrderManagement"/>
</bean>
我的 Pom.xml 看起来像这样:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
请忽略两个 # 符号,因为我的代表不是 10,所以我无法粘贴链接,我输入了那个符号, 无论如何,我的应用程序在出现上述错误后崩溃。我做错了什么?
更新的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
">
<mongo:mongo id="mongo" host="localhost" port="27017"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="ProcessOrderManagement"/>
</bean>
【问题讨论】:
-
/data/mongo/spring-mongo-1.0.xsd 而不是这个,只需定义 /data/mongo/spring-mongo.xsd 并重试
-
@BilboBaggins 试过了,同样的错误。抱歉没有提到我试过了。
-
您需要正确发布您的
context.xml。如果可能,完整文件,或至少前 30 行。一个字一个字。它在语法上不正确。
标签: java xml spring mongodb maven