Created
August 22, 2019 15:05
-
-
Save mchernyavskaya/cf60e8df18406751f9828d6d88bed2c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
class ExtraMongoConfiguration { | |
val uri: String? = null | |
val host: String? = null | |
val port: Int? = 0 | |
val database: String? = null | |
/** | |
* Method that creates MongoClient | |
*/ | |
private val mongoClient: MongoClient | |
get() { | |
if (uri != null && !uri.isNullOrEmpty()) { | |
return MongoClient(MongoClientURI(uri!!)) | |
} | |
return MongoClient(host!!, port!!) | |
} | |
/** | |
* Factory method to create the MongoTemplate | |
*/ | |
protected fun mongoTemplate(): MongoTemplate { | |
val factory = SimpleMongoDbFactory(mongoClient, database!!) | |
return MongoTemplate(factory) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment