Connection to MongoDB fails

I try to test the mflix application but it doesn’t connect to MongoDB.

If I try to connect with Mongo Shell it works.

Here’s the console output:

$ mvn -Dtest=ConnectionTest test
...
2021-01-18 18:18:07.536  INFO 3017 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[sandbox-shard-00-01.wtnpa.mongodb.net:27017, sandbox-shard-00-00.wtnpa.mongodb.net:27017, sandbox-shard-00-02.wtnpa.mongodb.net:27017], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='atlas-g2kgu5-shard-0'}
2021-01-18 18:18:07.536  INFO 3017 --- [           main] org.mongodb.driver.cluster               : Adding discovered server sandbox-shard-00-01.wtnpa.mongodb.net:27017 to client view of cluster
2021-01-18 18:18:07.559  INFO 3017 --- [           main] org.mongodb.driver.cluster               : Adding discovered server sandbox-shard-00-00.wtnpa.mongodb.net:27017 to client view of cluster
2021-01-18 18:18:07.560  INFO 3017 --- [           main] org.mongodb.driver.cluster               : Adding discovered server sandbox-shard-00-02.wtnpa.mongodb.net:27017 to client view of cluster
2021-01-18 18:18:07.826  INFO 3017 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2021-01-18 18:18:07.906  INFO 3017 --- [ngodb.net:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server sandbox-shard-00-00.wtnpa.mongodb.net:27017

com.mongodb.MongoSocketWriteException: Exception sending message
        at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:541) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:429) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:269) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:253) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:106) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.9.1.jar:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
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_45]
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937) ~[na:1.8.0_45]
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[na:1.8.0_45]
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) ~[na:1.8.0_45]
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1478) ~[na:1.8.0_45]
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212) ~[na:1.8.0_45]
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) ~[na:1.8.0_45]
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) ~[na:1.8.0_45]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1050) ~[na:1.8.0_45]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363) ~[na:1.8.0_45]
        at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:735) ~[na:1.8.0_45]
        at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123) ~[na:1.8.0_45]
        at com.mongodb.internal.connection.SocketStream.write(SocketStream.java:99) ~[mongodb-driver-core-3.9.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:426) ~[mongodb-driver-core-3.9.1.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_45]
        at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[na:1.8.0_45]
        at sun.security.validator.Validator.validate(Validator.java:260) ~[na:1.8.0_45]
        at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) ~[na:1.8.0_45]
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) ~[na:1.8.0_45]
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) ~[na:1.8.0_45]
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1460) ~[na:1.8.0_45]
        ... 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:145) ~[na:1.8.0_45]
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131) ~[na:1.8.0_45]
        at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) ~[na:1.8.0_45]
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) ~[na:1.8.0_45]
        ... 24 common frames omitted
...

Try upgrading to a more recent JDK.

OK, I have upgraded from JDK 1.8.0_45 to JDK 1.8.0_281 and now mflix works.
Thanks