Class MongoClientFactory

java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.MongoClient>
org.craftercms.commons.mongo.MongoClientFactory
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>, org.springframework.beans.factory.InitializingBean

public class MongoClientFactory extends org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.MongoClient>

Creates a Mongo Client based on a connection String

Connection String format host:PORT,[host1:port1],[hostN,portN] the port portion is optional default one 27017 will be use.

If connection String is null or empty or whitespace only, this factory will use as if connection String value is "127.0.0.1:27017"

Will throw IllegalArgumentException if port number is not valid

  • Field Details

  • Constructor Details

    • MongoClientFactory

      public MongoClientFactory()
  • Method Details

    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>
      Specified by:
      getObjectType in class org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.MongoClient>
    • createInstance

      protected com.mongodb.MongoClient createInstance() throws Exception
      Specified by:
      createInstance in class org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.MongoClient>
      Throws:
      Exception
    • setConnectionString

      public void setConnectionString(String connectionString)
    • setOptions

      public void setOptions(com.mongodb.MongoClientOptions options)
    • setUsername

      public void setUsername(String username)
    • setPassword

      public void setPassword(String password)