/spring-boot-issue-38611

Example application to demonstrate Spring Boot issue 38611

Primary LanguageJava

Issue

How to reproduce

Start the mongodb container with replication set replSet0

docker compose up

Build the app

mvn clean package

Run the application

java -Dspring.data.mongodb.uri=mongodb://localhost:27017/test?replicaSet=replSet0 -jar target/spring-boot-issue-38611-0.0.1-SNAPSHOT.jar

The java.lang.NoClassDefFoundError: com/mongodb/event/ServerClosedEvent can be seen in the logs when the app tries to start up.

There are other errors too, but this is because the app cannot reach the mongodb host under the hostname defined in the replication set. On the other side it seems that the NoClassDefFoundError maybe triggered because of the app trying to remove some host from the mongo replication set.

With all hosts being reachable I wasn’t able to provoke the error message.

Output

java -Dspring.data.mongodb.uri=mongodb://localhost:27017/test?replicaSet=replSet0 -jar target/spring-boot-issue-38611-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.0)

2023-12-07T10:34:56.695+01:00  INFO 170097 --- [           main] com.example.Application                  : Starting Application v0.0.1-SNAPSHOT using Java 21.0.1 with PID 170097 (/home/msievers/github/msievers/spring-boot-issue-38611/target/spring-boot-issue-38611-0.0.1-SNAPSHOT.jar started by msievers in /home/msievers/github/msievers/spring-boot-issue-38611)
2023-12-07T10:34:56.697+01:00  INFO 170097 --- [           main] com.example.Application                  : No active profile set, falling back to 1 default profile: "default"
2023-12-07T10:34:56.913+01:00  INFO 170097 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2023-12-07T10:34:56.923+01:00  INFO 170097 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 MongoDB repository interfaces.
2023-12-07T10:34:57.098+01:00  INFO 170097 --- [           main] org.mongodb.driver.cluster               : Adding discovered server localhost:27017 to client view of cluster
2023-12-07T10:34:57.136+01:00  INFO 170097 --- [           main] org.mongodb.driver.client                : MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|spring-boot", "version": "4.11.1"}, "os": {"type": "Linux", "name": "Linux", "architecture": "amd64", "version": "5.15.0-89-generic"}, "platform": "Java/Oracle Corporation/21.0.1+12-jvmci-23.1-b19"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, transportSettings=null, streamFactoryFactory=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@5754de72, com.mongodb.Jep395RecordCodecProvider@31ee96f4, com.mongodb.KotlinCodecProvider@320494b6]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[localhost:27017], srvServiceName=mongodb, mode=MULTIPLE, requiredClusterType=REPLICA_SET, requiredReplicaSetName='replSet0', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null}
2023-12-07T10:34:57.154+01:00  INFO 170097 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=17, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=16822480, setName='replSet0', canonicalAddress=mongodb-1:27017, hosts=[mongodb-1:27017], passives=[], arbiters=[], primary='mongodb-1:27017', tagSet=TagSet{[]}, electionId=7fffffff0000000000000002, setVersion=1, topologyVersion=TopologyVersion{processId=65718baf8ad2d7a3dcf93954, counter=6}, lastWriteDate=Thu Dec 07 10:34:53 CET 2023, lastUpdateTimeNanos=5602607671524}
2023-12-07T10:34:57.157+01:00  INFO 170097 --- [localhost:27017] org.mongodb.driver.cluster               : Adding discovered server mongodb-1:27017 to client view of cluster
2023-12-07T10:34:57.159+01:00  INFO 170097 --- [localhost:27017] org.mongodb.driver.cluster               : Server localhost:27017 is no longer a member of the replica set.  Removing from client view of cluster.
Exception in thread "cluster-ClusterId{value='657191c118a9ae08b26622e0', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/event/ServerClosedEvent
	at com.mongodb.internal.connection.DefaultServer.close(DefaultServer.java:172)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.removeExtraHosts(AbstractMultiServerCluster.java:436)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.ensureServers(AbstractMultiServerCluster.java:407)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.handleReplicaSetMemberChanged(AbstractMultiServerCluster.java:248)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.lambda$onChange$3(AbstractMultiServerCluster.java:197)
	at com.mongodb.internal.Locks.lambda$withInterruptibleLock$1(Locks.java:53)
	at com.mongodb.internal.Locks.checkedWithInterruptibleLock(Locks.java:66)
	at com.mongodb.internal.Locks.withInterruptibleLock(Locks.java:59)
	at com.mongodb.internal.Locks.withInterruptibleLock(Locks.java:52)
	at com.mongodb.internal.connection.BaseCluster.withLock(BaseCluster.java:226)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.withLock(AbstractMultiServerCluster.java:54)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.onChange(AbstractMultiServerCluster.java:165)
	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:113)
	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.lambda$update$0(DefaultSdamServerDescriptionManager.java:75)
	at com.mongodb.internal.Locks.lambda$withInterruptibleLock$1(Locks.java:53)
	at com.mongodb.internal.Locks.checkedWithInterruptibleLock(Locks.java:66)
	at com.mongodb.internal.Locks.withInterruptibleLock(Locks.java:59)
	at com.mongodb.internal.Locks.withInterruptibleLock(Locks.java:52)
	at com.mongodb.internal.connection.BaseCluster.withLock(BaseCluster.java:226)
	at com.mongodb.internal.connection.AbstractMultiServerCluster.withLock(AbstractMultiServerCluster.java:54)
	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:60)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:169)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: com.mongodb.event.ServerClosedEvent
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104)
	at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 23 more
2023-12-07T10:34:57.167+01:00  INFO 170097 --- [mongodb-1:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server mongodb-1:27017

com.mongodb.MongoSocketException: mongodb-1: Name or service not known
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:221) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.ServerAddressWithResolver.getSocketAddresses(ServerAddressWithResolver.java:68) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:100) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:78) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:211) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:196) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:156) ~[mongodb-driver-core-4.11.1.jar!/:na]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
Caused by: java.net.UnknownHostException: mongodb-1: Name or service not known
	at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
	at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52) ~[na:na]
	at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1211) ~[na:na]
	at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1828) ~[na:na]
	at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1139) ~[na:na]
	at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1818) ~[na:na]
	at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1688) ~[na:na]
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:213) ~[mongodb-driver-core-4.11.1.jar!/:na]
	... 7 common frames omitted

2023-12-07T10:34:57.318+01:00  INFO 170097 --- [           main] com.example.Application                  : Started Application in 0.849 seconds (process running for 1.108)
2023-12-07T10:34:57.322+01:00  WARN 170097 --- [ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter    : Invocation of close method failed on bean with name 'mongo': java.lang.NoClassDefFoundError: com/mongodb/event/ServerClosedEvent