Class MongoClientFactoryBean

java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>
org.springframework.data.mongodb.core.MongoClientFactoryBean
All Implemented Interfaces:
Aware, BeanClassLoaderAware, BeanFactoryAware, DisposableBean, FactoryBean<com.mongodb.client.MongoClient>, InitializingBean, PersistenceExceptionTranslator

public class MongoClientFactoryBean extends AbstractFactoryBean<com.mongodb.client.MongoClient> implements PersistenceExceptionTranslator
Convenient factory for configuring MongoDB.
Author:
Christoph Strobl, Mark Paluch
  • Constructor Details

    • MongoClientFactoryBean

      public MongoClientFactoryBean()
  • Method Details

    • setMongoClientSettings

      public void setMongoClientSettings(@Nullable com.mongodb.MongoClientSettings mongoClientOptions)
      Set the MongoClientSettings to be used when creating MongoClient.
      Parameters:
      mongoClientOptions -
    • setCredential

      public void setCredential(@Nullable com.mongodb.MongoCredential[] credential)
      Set the list of credentials to be used when creating MongoClient.
      Parameters:
      credential - can be null.
    • setHost

      public void setHost(@Nullable String host)
      Configures the host to connect to.
      Parameters:
      host -
    • setPort

      public void setPort(int port)
      Configures the port to connect to.
      Parameters:
      port -
    • setConnectionString

      public void setConnectionString(@Nullable com.mongodb.ConnectionString connectionString)
    • setReplicaSet

      public void setReplicaSet(@Nullable String replicaSet)
    • setExceptionTranslator

      public void setExceptionTranslator(@Nullable PersistenceExceptionTranslator exceptionTranslator)
      Configures the PersistenceExceptionTranslator to use.
      Parameters:
      exceptionTranslator -
    • getObjectType

      public Class<? extends com.mongodb.client.MongoClient> getObjectType()
      Specified by:
      getObjectType in interface FactoryBean<com.mongodb.client.MongoClient>
      Specified by:
      getObjectType in class AbstractFactoryBean<com.mongodb.client.MongoClient>
    • translateExceptionIfPossible

      @Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex)
      Specified by:
      translateExceptionIfPossible in interface PersistenceExceptionTranslator
    • createInstance

      protected com.mongodb.client.MongoClient createInstance() throws Exception
      Specified by:
      createInstance in class AbstractFactoryBean<com.mongodb.client.MongoClient>
      Throws:
      Exception
    • computeClientSetting

      protected com.mongodb.MongoClientSettings computeClientSetting()
      Create MongoClientSettings based on configuration and priority (lower is better).
      1. mongoClientSettings
      2. connectionString
      3. default MongoClientSettings
      Since:
      3.0
    • destroyInstance

      protected void destroyInstance(@Nullable com.mongodb.client.MongoClient instance) throws Exception
      Overrides:
      destroyInstance in class AbstractFactoryBean<com.mongodb.client.MongoClient>
      Throws:
      Exception