[英]MongoDB Atlas Error for java mongo java driver 3.4.0 and above
[英]MongoDB Atlas Java Driver TLS Issue
我有一個基於 Java 的服務器,使用 openjdk:15-jdk-alpine 在 Docker 中運行。 它使用 mongodb-driver-reactivestreams 驅動程序連接到 MongoDB Atlas。 同樣,我有第二個基於 SpringBoot 的服務器在 Docker 中運行,它使用相同的憑據進行連接並且運行良好。
當我在 IntelliJ 中運行我的代碼時,它運行沒有錯誤,連接到 MongoDB,我可以查詢、插入文檔等...
When I put it in a Docker container and spin up the server, I get the following error message: Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.internal.connection.tlschannel.TlsChannel
當我在連接字符串中使用tls=false
禁用 tls 時,我收到消息MongoSocketReadException: Prematurely reached end of stream
。
在這兩種情況下,當查看日志時,我可以看到服務器能夠識別我的 MongoDB 集群中的所有分片,因此它正在連接到 Mongo Atlas 並接收回信息。
我目前的理論是 1) Tls 需要連接 2) Tls 在我的 docker 容器中由於某種原因與 JVM 密鑰庫/信任庫有關。
我對 TLS 或 Java 密鑰庫的東西了解不夠,無法調試它,也不知道要搜索什么才能得到答案。 如果有人能指出我正確的方向,將不勝感激......
2021-10-14 17:58:53.730 DEBUG c608e84d3bb5 --- [ main] u.s.PropertiesServiceImpl : Looking for profiles.
2021-10-14 17:58:53.734 INFO c608e84d3bb5 --- [ main] u.s.PropertiesServiceImpl : Profile found: dev
2021-10-14 17:58:53.773 DEBUG c608e84d3bb5 --- [ main] c.p.s.c.SocketAcceptor : Creating server Socket at port: 6666
2021-10-14 17:58:53.788 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Connecting to Redis: localhost/6379
2021-10-14 17:58:53.872 DEBUG c608e84d3bb5 --- [ main] r.u.Loggers : Using Slf4j logging framework
2021-10-14 17:58:54.249 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:54.764 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:55.273 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:55.783 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:56.298 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:56.810 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:57.322 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:57.834 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:58.347 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:58.857 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...
2021-10-14 17:58:59.358 DEBUG c608e84d3bb5 --- [ main] s.r.s.RedisConnectionImpl : Redis connection could not be established!
2021-10-14 17:58:59.554 DEBUG c608e84d3bb5 --- [ main] .s.r.s.GameControllerImpl : Starting Room Manager
2021-10-14 17:58:59.646 INFO c608e84d3bb5 --- [ main] c.p.s.m.s.MongoDB : Mongodb target is: mongodb+srv://XXXXX:XXXXX@XXXXXX.erble.gcp.mongodb.net/xxxxxxx?retryWrites=true&w=majority
2021-10-14 17:58:59.667 DEBUG c608e84d3bb5 --- [ main] c.p.s.m.s.MongoDB : Starting MongoDb database...
2021-10-14 17:58:59.680 INFO c608e84d3bb5 --- [ main] o.m.d.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], srvHost=XXXXXX.erble.gcp.mongodb.net, mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', requiredReplicaSetName='XXXXXX-shard-0'}
2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [ main] c.p.s.m.s.MongoDB : MongoDb client initialised.
2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [ main] c.p.s.m.s.MongoDB : MongoDb client initialised.
2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [ main] c.p.s.Application : Starting server...
2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [ AcceptorThread] c.p.s.c.SocketAcceptor : Starting Socket acceptor loop...
2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [ProcessorThread] c.p.s.c.SocketProcessor : Starting Socket processor loop...
2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [ ReaderThread] c.p.s.c.SocketReader : Starting Socket reader loop...
2021-10-14 17:58:59.701 DEBUG c608e84d3bb5 --- [ WriterThread] c.p.s.c.SocketWriter : Starting Socket writer loop...
2021-10-14 17:58:59.702 DEBUG c608e84d3bb5 --- [ Thread-5] c.p.s.c.MessageReceiver : Starting loop.
2021-10-14 17:58:59.702 DEBUG c608e84d3bb5 --- [ main] c.p.s.m.s.MongoDB : MongoDb client initialised.
2021-10-14 17:58:59.744 INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster : Adding discovered server XXXXXX-shard-00-01.erble.gcp.mongodb.net:27017 to client view of cluster
2021-10-14 17:58:59.766 INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster : Adding discovered server XXXXXX-shard-00-02.erble.gcp.mongodb.net:27017 to client view of cluster
2021-10-14 17:58:59.768 INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster : Adding discovered server XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017 to client view of cluster
2021-10-14 17:58:59.770 DEBUG c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster : Updating cluster description to {type=REPLICA_SET, servers=[{address=XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=XXXXXX-shard-00-01.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=XXXXXX-shard-00-02.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]
2021-10-14 17:59:00.093 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:6}
2021-10-14 17:59:00.093 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:2}
2021-10-14 17:59:00.094 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:5}
2021-10-14 17:59:00.095 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:3}
2021-10-14 17:59:00.095 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:1}
2021-10-14 17:59:00.096 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection : Closing connection connectionId{localValue:4}
2021-10-14 17:59:00.095 INFO c608e84d3bb5 --- [ngodb.net:27017] o.m.d.cluster : Exception in monitor thread while connecting to server XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017
com.mongodb.MongoInternalException: Opening the TlsChannelStream failed
at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.get(AsynchronousChannelStream.java:328)
at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.getOpen(AsynchronousChannelStream.java:304)
at com.mongodb.internal.connection.AsynchronousChannelStream.open(AsynchronousChannelStream.java:125)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:165)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:195)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.internal.connection.tlschannel.TlsChannel
at com.mongodb.internal.connection.tlschannel.TlsChannelBuilder.<init>(TlsChannelBuilder.java:37)
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:45)
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:40)
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel.newBuilder(ClientTlsChannel.java:87)
at com.mongodb.connection.TlsChannelStreamFactoryFactory$TlsChannelStream.lambda$openAsync$0(TlsChannelStreamFactoryFactory.java:236)
at com.mongodb.connection.TlsChannelStreamFactoryFactory$SelectorMonitor.lambda$start$0(TlsChannelStreamFactoryFactory.java:141)
... 1 more
This issue is very likely to be connected with this (already fixed) bug https://jira.mongodb.org/browse/JAVA-4656 (driver fails to parse java.version
property if it contains only dashes and no dots, 15
, 15.0.1
或15.0.1-something
工作正常,但15-whatever
失敗)
所以解決方案是將您的 mongo 驅動程序更新到最新版本,或者將您的 java 版本更新為帶有一些點的版本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.