title: Mongo Java Driver version mismatch with spring framework
body: <p>I have springboot (2.0.4) application with Mongo Java driver version 3.11.2. When upgrading the application for mongo java driver to version 4.1.0 to use IAM authentication feature of new mongo java driver, the changes are breaking with overall spring framework.</p>
  <p>MongoTemplate Bean code:</p>
  <pre><code>@Bean
  public MongoClient mongoClient() {
      ConnectionString connectionString = new ConnectionString(
                      (&quot;mongodb://connectionString:goesHere&quot;));
      MongoClient mongoClient = MongoClients.create(connectionString);
      return mongoClient;
  }
  @Bean
  public MongoTemplate mongoTemplate(MongoClient mongoClient) {
      return new MongoTemplate(mongoClient, mongoDB);
  }
  </code></pre>
  <p>Dependencies:</p>
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
          &lt;artifactId&gt;mongodb-driver-sync&lt;/artifactId&gt;
          &lt;version&gt;4.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
          &lt;artifactId&gt;bson&lt;/artifactId&gt;
          &lt;version&gt;4.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
          &lt;artifactId&gt;mongodb-driver-core&lt;/artifactId&gt;
          &lt;version&gt;4.1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-data-commons&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
                  &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
                  &lt;artifactId&gt;mongodb-driver&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependecy&gt;
  </code></pre>
  <p>Deployment error with Mongo Java Driver 4.1.0:</p>
  <blockquote>
  <p>Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.util.Assert.noNullElements(Ljava/util/Collection;Ljava/lang/String;)V</p>
  </blockquote>
  <p>When looking into this issue, found that I need to add sping-core (5.2.5 or later) for this, that in turn is asking for other spring dependencies to be on same version.</p>
  <p>This whole defeats the goal of having spring boot for ease of dependency management.
  It feels like spring ecosystem has become so complex, that upgrading mongo-java-driver would need the un-necessary work of upgrading the whole application to newer version of springboot which are not backward compatible and will break the application build. Any suggestions to get rid of this issue.</p>