0

Using Spring Boot Starter Web dependency with the latest MongoDB driver 3.11.0 gives the below error. When I switch to an older version of Mongo Driver like 3.8.2, this works fine. Any ideas? Should I exclude a Mongo dependency?

If I remove the spring boot dependency, Mongo connections work fine.

06:39:09.046 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[host1:27017, host2:27017, host3:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
06:39:09.048 [main] INFO org.mongodb.driver.cluster - Adding discovered server host1:27017 to client view of cluster
06:39:09.079 [main] INFO org.mongodb.driver.cluster - Adding discovered server host2:27017 to client view of cluster
06:39:09.080 [main] INFO org.mongodb.driver.cluster - Adding discovered server host3:27017 to client view of cluster
06:39:09.083 [main] DEBUG org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=host3:27017, type=UNKNOWN, state=CONNECTING}, {address=host1:27017, type=UNKNOWN, state=CONNECTING}, {address=host2:27017, type=UNKNOWN, state=CONNECTING}]
Exception in thread "main" java.lang.NoSuchMethodError: com.mongodb.MongoClientSettings.getAutoEncryptionSettings()Lcom/mongodb/AutoEncryptionSettings;
    at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:67)
    at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:61)
    at com.mongodb.client.MongoClients.create(MongoClients.java:114)
    at com.mongodb.client.MongoClients.create(MongoClients.java:99)
    at com.mongodb.client.MongoClients.create(MongoClients.java:83)
    at com.mongodb.client.MongoClients.create(MongoClients.java:61)
    at com.mongo.demo.MongoDemo.main(MongoDemo.java:98)

pom below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mongo-test</groupId>
  <artifactId>mongo-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>mongo-test</name>
  <description>Mongo Test</description>
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
    </parent>
  <dependencies>
      <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>3.11.0</version>
    </dependency>
            <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
           <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

        </dependency> 
  </dependencies>
             <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
1
  • Can you try my answer? Commented Sep 18, 2019 at 5:58

2 Answers 2

6

Can you try this dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

instead of

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>3.11.0</version>
</dependency>
Sign up to request clarification or add additional context in comments.

1 Comment

This is the answer if you are using Spring Boot.
1

Some dependency issue with Spring Boot. I solved it by the below :

  <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>bson</artifactId>
       <version>3.11.0</version>
  </dependency>
  <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver</artifactId>
      <version>3.11.0</version>
      <exclusions>
          <exclusion>
               <groupId>org.mongodb</groupId> 
               <artifactId>bson</artifactId>
           </exclusion>
      </exclusions>
  </dependency>
  <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-core</artifactId>
      <version>3.11.0</version>
  </dependency> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.