今天在spring中整合mongodb,我参考官网的配置配置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:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation=
"http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Default bean name is 'mongo' -->
<mongo:mongo host="${mongo.address}" port="27017" />
</beans>
因为我的spring以及spring-boot版本都较低,因为用的是mongo:mongo
而不是mongo:mongo-client
,结果启动报错
Caused by: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 57; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'mongo:mongo' 的声明
于是网上搜索,什么版本不对,schema没有添加,结果还是一样没用,突然发现这里的schema
有以https
开头的,莫非是访问不了?于是全改成http
,OK了。
来源:CSDN
作者:zlp1992
链接:https://blog.csdn.net/zlp1992/article/details/103805079