I am migrating a jar from using the 3.0 version of mongo driver to 5.1. I am using java SE 11. In my local environment, the tests work ok, but when in the web environment, I get the following error:
java.lang.NoSuchMethodError: 'void com.mongodb.MongoClient.< init >(java.util.List, java.util.List, com.mongodb.MongoClientOptions)' at deployment.VUCE.war//com.genexusconsulting.mongodb.GXCMongoDBConector.createClient(GXCMongoDBConector.java:811) at deployment.VUCE.war//com.genexusconsulting.mongodb.GXCMongoDBConector.connect(GXCMongoDBConector.java:106)
The line that is referring to has the following code:
List<ServerAddress> seeds = new ArrayList<ServerAddress>();
seeds.add(new ServerAddress(host, port));
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(CodecRegistries.fromProviders(new QueryResponseCodecProvider()), MongoClientSettings.getDefaultCodecRegistry());
ConnectionString cnn = new ConnectionString(mongoUri);
/* here there be error */
MongoClientSettings options = MongoClientSettings.builder().
applyConnectionString(cnn).
applyToClusterSettings(builder -> builder.hosts(seeds)).
codecRegistry(codecRegistry).build();
/* here there be error */
The pom file includes:
<!-- https://mvnrepository.com/artifact/org.mongodb/bson -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>5.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-core -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>5.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>5.1.2</version>
</dependency>
For which, the files that I include on my lib folder are: bson-5.1.2.jar, bson-record-codec-5.1.2, mongodb-driver-core-5.1.2.jar and mongodb-driver-sync-5.1.2.jar, while also removing all previous versions. The code works fine in my local tests, but it fails when I include it in a test environment.