spring boot 连接mongodb报错 Exc sending message CertificateException

发布于 2022-09-07 08:31:07 字数 4488 浏览 8 评论 0

本地启动项目报错,
同样的代码配置,才别人那里没有问题,
求解什么原因,

{"exception":"com.mongodb.MongoSocketWriteException: Exception sending
messagerntat
com.mongodb.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:516)rntat
com.mongodb.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:404)rntat
com.mongodb.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:269)rntat
com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:252)rntat
com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)rntat
com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)rntat
com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:91)rntat
com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:51)rntat
com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)rntat
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)rntat
java.lang.Thread.run(Thread.java:745)rnCaused by:
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative names
matching IP address 18.233.195.78 foundrntat
sun.security.ssl.Alerts.getSSLException(Alerts.java:192)rntat
sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)rntat
sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)rntat
sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)rntat
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1506)rntat
sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)rntat
sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)rntat
sun.security.ssl.Handshaker.process_record(Handshaker.java:914)rntat
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)rntat
sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)rntat
sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)rntat
sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)rntat
com.mongodb.connection.SocketStream.write(SocketStream.java:74)rntat
com.mongodb.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:401)rnt...
9 morernCaused by: java.security.cert.CertificateException: No
subject alternative names matching IP address 18.233.195.78
foundrntat
sun.security.util.HostnameChecker.matchIP(HostnameChecker.java:167)rntat
sun.security.util.HostnameChecker.match(HostnameChecker.java:93)rntat
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455)rntat
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436)rntat
sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:200)rntat
sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)rntat
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1488)rnt...
18
morern","thread_id":46,"level":"INFO","logger_name":"org.mongodb.driver.cluster","time":"2018-05-21T10:43:27.437+08:00","message":"Exception
in monitor thread while connecting to server
cluster0-shard-00-01-ta2km.mongodb.net:27017"}

代码:

@SpringBootApplication(exclude = { SessionAutoConfiguration.class, DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class,MongoAutoConfiguration.class })
public class App {
    ...
}
 
@Component
public class MongoDBHelper {
 
    @Value("${mongoClient.uri}")
    private String mongoClientUri;
 
    @Value("${dbName}")
    private String databaseName;
 
    private static MongoClient mongoClient = null;
 
    public MongoDBHelper() {
    }
 
    @Bean
    public MongoClient getMongoClient() {
        if (mongoClient == null) {
            MongoClientURI uri = new MongoClientURI(mongoClientUri);
            mongoClient = new MongoClient(uri);
        }
        return mongoClient;
    }
 
    public MongoDatabase getMongoDataBase() {
        MongoDatabase database = getMongoClient().getDatabase(databaseName);
        return database;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2022-09-14 08:31:07

跟证书相关的问题。

  1. 先看看你们的服务端是否配置了证书;
  2. 看看是不是强制要求客户端证书;
  3. 其次要看证书是不是自签名的或是合法的第三方颁发的;

如果不清楚怎么看,最好问问你们配置MongoDB的人会比较清楚。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文