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
-
Field Summary
Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
logger
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected com.mongodb.MongoClientSettings
CreateMongoClientSettings
based on configuration and priority (lower is better).protected com.mongodb.client.MongoClient
protected void
destroyInstance
(com.mongodb.client.MongoClient instance) Class<? extends com.mongodb.client.MongoClient>
void
setConnectionString
(com.mongodb.ConnectionString connectionString) void
setCredential
(com.mongodb.MongoCredential[] credential) Set the list of credentials to be used when creatingMongoClient
.void
setExceptionTranslator
(PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslator
to use.void
Configures the host to connect to.void
setMongoClientSettings
(com.mongodb.MongoClientSettings mongoClientOptions) Set theMongoClientSettings
to be used when creatingMongoClient
.void
setPort
(int port) Configures the port to connect to.void
setReplicaSet
(String replicaSet) Methods 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
Set theMongoClientSettings
to be used when creatingMongoClient
.- Parameters:
mongoClientOptions
-
-
setCredential
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
-
setReplicaSet
-
setExceptionTranslator
Configures thePersistenceExceptionTranslator
to use.- Parameters:
exceptionTranslator
-
-
translateExceptionIfPossible
- Specified by:
translateExceptionIfPossible
in interfacePersistenceExceptionTranslator
-
getObjectType
- Specified by:
getObjectType
in interfaceFactoryBean<com.mongodb.client.MongoClient>
- Specified by:
getObjectType
in classAbstractFactoryBean<com.mongodb.client.MongoClient>
-
createInstance
- Specified by:
createInstance
in classAbstractFactoryBean<com.mongodb.client.MongoClient>
- Throws:
Exception
-
destroyInstance
- Overrides:
destroyInstance
in classAbstractFactoryBean<com.mongodb.client.MongoClient>
- Throws:
Exception
-
computeClientSetting
protected com.mongodb.MongoClientSettings computeClientSetting()CreateMongoClientSettings
based on configuration and priority (lower is better).mongoClientSettings
connectionString
- default
MongoClientSettings
- Since:
- 3.0
-