title: MongoTimeoutException when trying to insert using Spring boot application app on openshift
body: <p><strong>Issue</strong>:
      1. I am not using Spring Boot MongoAutoConfiguration because we need mongo to be optional. 
      2. Other applications in same namespace can access MongoDB and network namespace is same for Application namespace and database namespace.
      3. When I try to connect I get timeout exception. 
      4. Same worked on my local</p>
  
  <p><strong>POINTS ALREADY VERIFIED:</strong>
      1. Checked mongod is up and running. other app in same namepsace is able to access same but its using Spring Mongo implementation.
      2. no network issue.
      3. There are post in stackoverflow for same exception, Its already tested. Not working.</p>
  
  <p><strong>a) application.properties:</strong></p>
  
  <pre><code>mongo.hosts = mongo-node-1.database, mongo-node-2.database, mongo-node-3.database
  mongo.port = 27017
  mongo.database = database
  isMongoEnabled = true
  </code></pre>
  
  <p><strong>b) MongoClient bean :</strong></p>
  
  <pre><code>@Configuration
  public class MongoConfiguration {
  
      @Value("#{'${mongo.hosts}'.split(',')}")
      private List&lt;String&gt; hosts;
  
      @Value("${mongo.port}")
      private int port;
  
      @Value("${isMongoEnabled}")
      private boolean isMongoEnabled;
  
      @Value("${mongo.database}")
      private String database;
  
      private Mongo createMongo() throws Exception {
          final List&lt;ServerAddress&gt; serverList = new ArrayList&lt;&gt;();
          for (final String host : hosts) {
              serverList.add(new ServerAddress(host, port));
          }
          return new MongoClient(serverList);
      }
  
      @Bean 
      public Mongo mongoClient() throws Exception {
              final Mongo mongo = createMongo();
              return mongo;
      }
  
  
  }
  </code></pre>
  
  <p><strong>c) Template bean:</strong></p>
  
  <pre><code>@Configuration
  @EnableMongoRepositories(
          basePackages = "com.abc.test",
          mongoTemplateRef = "customMongoNodeTemplate"
  )
  
  @Import(MongoConfiguration.class)
  public class TemplateConfiguration {
      @Value("${mongo.database}")
          private String database;
  
  
          @Bean
          public MongoTemplate customMongoNodeTemplate(@Qualifier ("mongoClient") Mongo mongo) {
              final MongoDbFactory factory =  new SimpleMongoDbFactory( (MongoClient) mongo, database); 
              return new MongoTemplate(factory);
  
          }
  
  }
  </code></pre>
  
  <p><strong>d) Exception:</strong></p>
  
  <pre><code>com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
  </code></pre>
  
  <p>UPDATE: 
  After trying SimpleMongoClientDBFactory(uri) got below exception :</p>
  
  <ul>
  <li>Application.properties:</li>
  </ul>
  
  <pre><code>mongo.uri= mongodb://mongo-node-1.database:27017,mongo-node-2.database:27017,mongo-node-3.database:27017/database
  </code></pre>
  
  <p>Exception :</p>
  
  <pre><code>#com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
  </code></pre>
  
  <p>SPRING boot version :</p>
  
  <pre><code>2.1.6
  </code></pre>
  
  <p>Mongo version :</p>
  
  <pre><code>4.0.6
  </code></pre>
  
  <p>Mongo Driver Version:</p>
  
  <pre><code>3.8.2
  </code></pre>