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.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

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

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

Related

  • DGS GraphQL and Spring Boot
  • A Practical Guide to Creating a Spring Modulith Project
  • Setting Up Local Kafka Container for Spring Boot Application
  • Spring Boot Application With Spring REST and Spring Data MongoDB

Trending

  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  1. DZone
  2. Coding
  3. Frameworks
  4. Configuring Spring Boot Application Properties in Containerized Environment

Configuring Spring Boot Application Properties in Containerized Environment

In this article, we will see simple steps to centralize and externalize the configuration of a Spring Boot application in a containerized environment.

By 
Hemant Mandge user avatar
Hemant Mandge
·
Jul. 19, 22 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
5.2K Views

Join the DZone community and get the full member experience.

Join For Free

Until a few years ago, monolithic applications were common. With numerous functions knitted into the fabric of the codebase and interdependencies running through them, it was difficult — or even impossible — to work on individual functions in isolation. To add to the complexity, managing multiple environment-specific configuration was a nightmare. That is when Spring introduced the interesting feature of creation of multiple environment profiles with application.properties /application.yml. Creating a bunch of application-[profile].properties files like application-local.yml, application-test.yml, application-dev.yml was very common in those days to create different environment-specific configurations.

Fast Forward to Today

As the technology progressed, soon organizations started adapting modern ways of not only developing the application, but also deploying them. With introduction of microservices architecture and containerization technologies like Kubernetes and Docker, there came the inherent need of managing and deploying it in a cleaner way. 

Externalizing configuration properties is one of the 12 factors and guidelines for building cloud-native applications. 

With the introduction of Kubernetes, soon the need for maintaining those bunches of environment-specific file ended and was replaced by configuration in Kubernetes manifest files, or ConfigMaps, along with secrets/Azure key vault for sensitive information.

With modern containerization technologies like Kubernetes and Docker, are multiple environment-specific Spring Boot application.properties still relevant? Not really!

All that is needed is single application.properties or application.yml with placeholder like ${AZURE_STORAGE_ENDPOINT} that will be injected with Kubernetes manifest files or ConfigMaps.

Below is an example of how application.yml with a placeholder will look. 


Developers' Corner

With this, obviously developers who used to run applications with application-local.yml would be interested in knowing the way to run application in their IDE. Here is the way to do it in IntelliJ, as mentioned on jetbrains.com:

Add Environment Variables

  1. From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar.
  2. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to.
  3. Type the variable name and value: <name>=<value>. If you want to add a few variables, separate them with semicolons;.

To escape the semicolon, use the backslash: VAR=one\;two.

Alternatively, click the notepad icon, and add the variable name and value to the User environment variables list. 



Conclusion

Hopefully, these simple steps will help to centralize and externalize the configuration of Spring Boot applications in a containerized environment. Also, these steps will enable developers to stop having to maintain a bunch of environment-specific application.yml/application.properties files. Only a single application.yml/application.properties file with placeholders like ${PROPERTY_VALUE} to inject values of the properties run time is needed. The same will be injected by container management platforms like Kubernetes. This will help with "Externalizing Configuration Properties," which is one of the 12 factors and guidelines for building cloud-native applications.

application Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • DGS GraphQL and Spring Boot
  • A Practical Guide to Creating a Spring Modulith Project
  • Setting Up Local Kafka Container for Spring Boot Application
  • Spring Boot Application With Spring REST and Spring Data MongoDB

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!