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
Please enter at least three characters to search
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Trending

  • Cloud Cost Optimization for ML Workloads With NVIDIA DCGM
  • Navigating the LLM Landscape: A Comparative Analysis of Leading Large Language Models
  • How AI Is Changing the Way Developers Write Code
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  1. DZone
  2. Coding
  3. Frameworks
  4. Creating a Spring Boot Configuration Server Using a Database

Creating a Spring Boot Configuration Server Using a Database

Not many people talk about how to create a Spring Boot configuration server with a database as opposed to a file system or git repository. But here's how to do it.

By 
Dursun Koç user avatar
Dursun Koç
DZone Core CORE ·
Updated Apr. 12, 19 · Tutorial
Likes (23)
Comment
Save
Tweet
Share
56.7K Views

Join the DZone community and get the full member experience.

Join For Free

You can find many articles on the internet about creating a Spring Boot configuration server using either a file system or git repository, but this is not true for a configuration server based on a database. In this article, I am going to discuss reasons to use a database as a configuration server and demonstrate how to create it using Spring Boot.

Storing configurations on a database seems to be a better idea than storing it on either a file system or git. Because it is less trackable, it is less secure. I admit that git has security and tracking options, but they seem to be complicated for a developer. However, tracking a database table is just creating a trigger for updates, and securing a database is not an issue for a developer. Again, changing a value in a database table is just so simple and easy to commit; however, it can be a cumbersome task to make a change in a git repository.

The overall architecture is as follows:

Image title

Once you have created your Spring Boot project from the Spring initializer, you need to add the following dependencies to your pom.xml file:

...

<!-- CONFIG SERVER -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- /CONFIG SERVER -->
<!-- JDBC -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<!-- Your database driver dependencies here -->
</dependency>
<!-- /JDBC -->

...

Next, you will need to create a table in your database to store the configuration:

CREATE TABLE my_properties 
  ( 
     application VARCHAR(200), 
     profile     VARCHAR(200), 
     label       VARCHAR(200), 
     KEY         VARCHAR(200), 
     value       VARCHAR(200) 
  ) 

Finally, you will need to configure your configuration server with a application.yml file as shown below:

...
spring:
  cloud:
    config:
      server:
        jdbc:
          sql: SELECT KEY, VALUE from  MY_PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
          order: 1 
  datasource:
    url: <your db url here>
    driver-class-name: <your databases driver class here>
    username: <your user to database>
    password: 
    hikari:
      maximum-pool-size: 10
      connection-timeout: 5000
  profiles:
    active:
    - jdbc
...

Now, you can test your configuration server with a configuration client.

Here is a sample project.

https://github.com/dursunkoc/samplespringbootdbconfigserver

Spring Framework Database Spring Boot File system

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Partner Resources

×

Comments
Oops! Something Went Wrong

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
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!