DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation

Trending

  • Automating E2E Tests With MFA: Streamline Your Testing Workflow
  • Testing the MongoDB MCP Server Using SingleStore Kai
  • Building V1 Gen-AI Products at Scale: Technical Product Patterns That Work
  • Beyond Java Streams: Exploring Alternative Functional Programming Approaches in Java
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Bootstrapping Spring Cloud Config Server MongoDB

Bootstrapping Spring Cloud Config Server MongoDB

Bootstrapping a configuration server with Spring Cloud Config Server MongoDB is just a matter of three steps. Learn what they are and look at a usage example!

By 
Venil Noronha user avatar
Venil Noronha
·
Sep. 05, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
8.6K Views

Join the DZone community and get the full member experience.

Join For Free

Spring Cloud Config Server MongoDB enables the seamless integration of the regular Spring Cloud Config Server with MongoDB to manage external properties for applications across all environments.

A Simple Config Server

Bootstrapping a configuration server with Spring Cloud Config Server MongoDB is just a matter of the following three steps.

  1. Configure your pom.xml:

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server-mongodb</artifactId>
            <version>0.0.2.BUILD-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/libs-snapshot-local</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>ojo-snapshots</id>
            <name>OJO Snapshots</name>
            <url>https://oss.jfrog.org/artifactory/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
  2. Create a standard Spring Boot application with the EnableMongoConfigServer annotation:

    @SpringBootApplication
    @EnableMongoConfigServer
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }
  3. Configure the application's spring.data.mongodb.* properties in application.yml:

    spring:
      data:
        mongodb:
          uri: mongodb://localhost/config-db

Usage

We can now add configuration documents to MongoDB and access it via the REST API.

  1. Add configuration documents to MongoDB:

    use config-db;
    
    db.gateway.insert({
      "label": "master",
      "profile": "prod",
      "source": {
        "user": {
          "max-connections": 1,
          "timeout-ms": 3600
        }
      }
    });
  2. Access it by invoking  http://localhost:8080/master/gateway-prod.properties:

    user.max-connections: 1.0
    user.timeout-ms: 3600.0

Spring Cloud Config Client-backed components can be configured to automatically load configuration from MongoDB by leveraging Spring Cloud Config Server MongoDB. See here for an example!

Like it? Give the project a star on GitHub. You can also comment below. All feedback is welcome!

Spring Cloud Spring Framework MongoDB

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: