Java 当我将Mongo与Spring一起使用时,应用程序崩溃
我的应用程序在启动时崩溃,出现错误: 原因:org.xml.sax.saxpasseeption;行号:13;栏目号:60;cvc复杂类型.2.4.c:匹配的通配符是严格的,但找不到元素“mongo:mongo”的声明 My context.xml如下所示:Java 当我将Mongo与Spring一起使用时,应用程序崩溃,java,xml,spring,mongodb,maven,Java,Xml,Spring,Mongodb,Maven,我的应用程序在启动时崩溃,出现错误: 原因:org.xml.sax.saxpasseeption;行号:13;栏目号:60;cvc复杂类型.2.4.c:匹配的通配符是严格的,但找不到元素“mongo:mongo”的声明 My context.xml如下所示: xsi:schemaLocation=" http##://www.springframework.org/schema/beans http##://www.springframework.org/schema/beans/spring-
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>
<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>
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“>
我的Pom.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>
<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>
org.springframework.data
spring数据mongodb
1.8.2.1发布
org.mongodb
mongo java驱动程序
3.2.0
org.mongodb.morphia
吗啡
1.0.1
org.springframework.data
spring数据共享
1.5.0.1发布
请忽略两个#符号,因为我的代表不是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>
您的context.xml可能粘贴错误,或者您的错误是context.xml未正确打开。缺少开始的xml文档标记。注意这个例子的顶部 更新:如果您没有spring上下文名称空间,还需要注意它
<?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:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation=
"http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Default bean name is 'mongo' -->
<mongo:mongo host="localhost" port="27017"/>
</beans>
/data/mongo/spring-mongo-1.0.xsd而不是这个,只需定义/data/mongo/spring-mongo.xsd并重试again@BilboBaggins我试过了,同样的错误。抱歉,我没有提到我尝试过。您需要正确发布context.xml
。如果可能,完整文件,或至少前30行。一个字接一个字。这在语法上是不正确的。作为参考,这里找到的spring文档中的示例:我已经更新了XML,当我删除xmlns:mongo=”“和Hmm时,我的应用程序运行良好,这很奇怪,该模式确实存在,您可以在浏览器中导航到它。