This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Cloud Config 4.1.4!spring-doc.cn

MongoDB Backend

Spring Cloud Config Server supports MongoDB as a backend for configuration properties. You can enable this feature by adding spring-boot-starter-data-mongodb to the classpath and using the mongodb profile.spring-doc.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-mongodb</artifactId>
	</dependency>
</dependencies>

Configure your application’s application.properties or application.yml to point to your MongoDB instance:spring-doc.cn

spring:
  profiles:
    active: mongodb
  data:
    mongodb:
      database: your-database-name
      port: '27017'
      host: localhost

The configuration properties should be stored in documents within the properties collection. Each document represents a set of properties for a given application, profile, and label.spring-doc.cn

Example MongoDB document:spring-doc.cn

{
  "application": "myapp",
  "profile": "development",
  "label": "master",
  "properties": {
    "property1": "value1",
    "property2": "value2"
  }
}

You can disable autoconfiguration for MongoDbEnvironmentRepository by setting the spring.cloud.config.server.mongodb.enabled property to false.spring-doc.cn

The default values for MongoDB backend configuration are as follows:spring-doc.cn

  • Collection Name: "properties" (Name of the MongoDB collection to query for configuration properties.)spring-doc.cn

  • Default Label: "master" (Default label to use if none is specified.)spring-doc.cn

You can change these defaults by setting spring.cloud.config.server.mongodb.collection and spring.cloud.config.server.mongodb.defaultLabel in your application’s configuration.