title: Spring data mongodb, how to set SSL?
body: <p>I have so far failed to find a good explanation/doc on the topic.</p>
  
  <p>I am using </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
      &lt;version&gt;1.9.5.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>and my code looks like this:</p>
  
  <pre><code>   @Bean
     public MongoClientFactoryBean mongo() {
        MongoClientFactoryBean mongo = new MongoClientFactoryBean();
        mongo.setHost(host);
        mongo.setPort(port);
        mongo.setCredentials(new MongoCredential[]{MongoCredential.createCredential(username, database, password.toCharArray())});
        return mongo;
     }
  
     @Bean
     public MongoTemplate mongoTemplate(Mongo mongo) throws Exception {
        return new MongoTemplate(mongo, database);
     }
  </code></pre>
  
  <p>Do you know how I should configure SSL for this?  And can I allow invalid certificate?</p>
  
  <p>The equivalent mongo command line would be</p>
  
  <pre><code>mongo --ssl --sslAllowInvalidCertificates --host &lt;host&gt; --port &lt;port&gt;
  </code></pre>