Class MongoClientFactoryBean
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>
org.springframework.data.mongodb.core.MongoClientFactoryBean
- 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.client.MongoClient>,org.springframework.beans.factory.InitializingBean,org.springframework.dao.support.PersistenceExceptionTranslator
public class MongoClientFactoryBean
extends org.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>
implements org.springframework.dao.support.PersistenceExceptionTranslator
Convenient factory for configuring MongoDB.
- Author:
- Christoph Strobl, Mark Paluch
-
Field Summary
Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.mongodb.MongoClientSettingsCreateMongoClientSettingsbased on configuration and priority (lower is better).protected com.mongodb.client.MongoClientprotected voiddestroyInstance(com.mongodb.client.MongoClient instance) Class<? extends com.mongodb.client.MongoClient>voidsetConnectionString(com.mongodb.ConnectionString connectionString) voidsetCredential(com.mongodb.MongoCredential[] credential) Set the list of credentials to be used when creatingMongoClient.voidsetExceptionTranslator(org.springframework.dao.support.PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslatorto use.voidConfigures the host to connect to.voidsetMongoClientSettings(com.mongodb.MongoClientSettings mongoClientOptions) Set theMongoClientSettingsto be used when creatingMongoClient.voidsetPort(int port) Configures the port to connect to.voidsetReplicaSet(String replicaSet) org.springframework.dao.DataAccessExceptionMethods inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
afterPropertiesSet, destroy, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingleton
-
Constructor Details
-
MongoClientFactoryBean
public MongoClientFactoryBean()
-
-
Method Details
-
setMongoClientSettings
public void setMongoClientSettings(@Nullable com.mongodb.MongoClientSettings mongoClientOptions) Set theMongoClientSettingsto be used when creatingMongoClient.- Parameters:
mongoClientOptions-
-
setCredential
public void setCredential(@Nullable com.mongodb.MongoCredential[] credential) Set the list of credentials to be used when creatingMongoClient.- Parameters:
credential- can be null.
-
setHost
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
-
setExceptionTranslator
public void setExceptionTranslator(@Nullable org.springframework.dao.support.PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslatorto use.- Parameters:
exceptionTranslator-
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<com.mongodb.client.MongoClient>- Specified by:
getObjectTypein classorg.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>
-
translateExceptionIfPossible
@Nullable public org.springframework.dao.DataAccessException translateExceptionIfPossible(RuntimeException ex) - Specified by:
translateExceptionIfPossiblein interfaceorg.springframework.dao.support.PersistenceExceptionTranslator
-
createInstance
- Specified by:
createInstancein classorg.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>- Throws:
Exception
-
computeClientSetting
protected com.mongodb.MongoClientSettings computeClientSetting()CreateMongoClientSettingsbased on configuration and priority (lower is better).mongoClientSettingsconnectionString- default
MongoClientSettings
- Since:
- 3.0
-
destroyInstance
- Overrides:
destroyInstancein classorg.springframework.beans.factory.config.AbstractFactoryBean<com.mongodb.client.MongoClient>- Throws:
Exception
-