今天在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了。