title: MongoDB: IllegalStateException: The pool is closed error message in Spring Boot application
body: <p>I'm getting this info message:</p>
  
  <blockquote>
    <p>19-October-24 08:05:53:481  INFO Thread-4 o.m.d.connection:71 - Closed
    connection [connectionId{localValue:35, serverValue:38}] to
    mongodb:27017 because the pool has been closed.</p>
  </blockquote>
  
  <p>And also the following errors:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: The pool is closed   at
    com.mongodb.internal.connection.ConcurrentPool.get(ConcurrentPool.java:137)
      at</p>
    
    <p>java.lang.IllegalStateException: state should be: open    at
    com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)</p>
  </blockquote>
  
  <p>This is how I'm creating the <code>MongoClient</code>, plain and simple:</p>
  
  <pre><code>@Bean
  @Override
  public MongoClient mongoClient() {
      return new MongoClient(host);
  }
  </code></pre>
  
  <p>This <a href="https://stackoverflow.com/a/39706712/10255450">SO answer</a> suggests to set <code>socketKeepAlive(true)</code> but as far as I understand this method is deprecated as it's true by default.</p>
  
  <ul>
  <li>I'm using MongoTemplate and MongoRepository.</li>
  <li>The application (as mentioned above) is multi-threaded.</li>
  </ul>
  
  <p>I'd like to understand what's the meaning of the error ? (i.e. Why would the pool ever be closed?).</p>
  
  <p>Do I need to set/adjust some Spring-Boot parameters maybe? Do I need to build MongoClient differently?</p>