mongodb-atlas与spring-boot

cwtwac6a  于 2021-07-04  发布在  Java
关注(0)|答案(1)|浏览(465)

我正在尝试连接mongodb atlas和spring boot。我有mongodb atlas uri连接字符串。

mongodb://root:<PASSWORD>@cluster0-shard-00-00.rbcol.mongodb.net:27017,cluster0-shard-00-01.rbcol.mongodb.net:27017,cluster0-shard-00-02.rbcol.mongodb.net:27017/invoicefinancing?ssl=true&replicaSet=atlas-i1vx5v-shard-0&authSource=admin&retryWrites=true&w=majority

将url设置为spring boot application.properties文件,如下所示

spring.data.mongodb.uri=mongodb://root:<PASSWORD>@cluster0-shard-00-00.rbcol.mongodb.net:27017,cluster0-shard-00-01.rbcol.mongodb.net:27017,cluster0-shard-00-02.rbcol.mongodb.net:27017/invoicefinancing?ssl=true&replicaSet=atlas-i1vx5v-shard-0&authSource=admin&retryWrites=true&w=majority

当我运行这个项目时,我发现了下面的错误。

com.mongodb.MongoSocketWriteException: Exception sending message
    at com.mongodb.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:518) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:406) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:270) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:253) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:91) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:51) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:127) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114) ~[mongodb-driver-core-3.6.4.jar:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72]
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.8.0_72]
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) ~[na:1.8.0_72]
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[na:1.8.0_72]
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) ~[na:1.8.0_72]
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) ~[na:1.8.0_72]
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) ~[na:1.8.0_72]
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) ~[na:1.8.0_72]
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) ~[na:1.8.0_72]
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) ~[na:1.8.0_72]
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_72]
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747) ~[na:1.8.0_72]
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123) ~[na:1.8.0_72]
    at com.mongodb.connection.SocketStream.write(SocketStream.java:74) ~[mongodb-driver-core-3.6.4.jar:na]
    at com.mongodb.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:403) ~[mongodb-driver-core-3.6.4.jar:na]
    ... 9 common frames omitted
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) ~[na:1.8.0_72]
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[na:1.8.0_72]
    at sun.security.validator.Validator.validate(Validator.java:260) ~[na:1.8.0_72]
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) ~[na:1.8.0_72]
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) ~[na:1.8.0_72]
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) ~[na:1.8.0_72]
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) ~[na:1.8.0_72]
    ... 18 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) ~[na:1.8.0_72]
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) ~[na:1.8.0_72]
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) ~[na:1.8.0_72]
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) ~[na:1.8.0_72]
    ... 24 common frames omitted

我怎样才能解决这个问题?谢谢

00jrzges

00jrzges1#

更新你的jdk,让我们加密证书应该在版本8u101中可用。

相关问题