{"id":3750,"date":"2025-12-19T10:00:01","date_gmt":"2025-12-19T15:00:01","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3750"},"modified":"2025-12-19T10:00:01","modified_gmt":"2025-12-19T15:00:01","slug":"mastering-multi-profile-environments-with-spring-cloud-config","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/mastering-multi-profile-environments-with-spring-cloud-config\/","title":{"rendered":"Mastering Multi-Profile Environments with Spring Cloud Config"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>Spring Cloud Config simplifies configuration management for microservices, but its power truly shines when dealing with diverse environments.  This post dives into how to leverage multiple profiles with Spring Cloud Config, giving you fine-grained control over your application\u2019s behavior.<\/p>\n<p><strong>Why Use Multiple Profiles?<\/strong><\/p>\n<p>Imagine your application needs different settings for development, testing, and production. Hardcoding these variations is messy and error-prone. Profiles let you define distinct sets of properties, activating the appropriate ones based on the environment.<\/p>\n<p><strong>Setting Up Profiles with Spring Cloud Config<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Organize Your Configuration Files:<\/strong><\/p>\n<p>Within your configuration repository (e.g., Git), structure your files to reflect your profiles. Here\u2019s a common approach:<\/p>\n<pre><code>\u251c\u2500\u2500 application.yml       # Default properties\n\u251c\u2500\u2500 application-dev.yml   # Development-specific properties\n\u251c\u2500\u2500 application-test.yml  # Test-specific properties\n\u2514\u2500\u2500 application-prod.yml  # Production-specific properties\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Activate Profiles in Your Application:<\/strong><\/p>\n<p>You have several ways to activate profiles:<\/p>\n<ul>\n<li>\n<p><strong><code>spring.profiles.active<\/code> Property:<\/strong> Set this property in your <code>application.properties<\/code> or <code>application.yml<\/code> (or as an environment variable).<\/p>\n<pre><code class=\"language-yaml\">spring:\n  profiles:\n    active: dev\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Command-Line Arguments:<\/strong> Pass profiles when starting your application:<\/p>\n<pre><code class=\"language-bash\">java -jar myapp.jar --spring.profiles.active=dev\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Profile-Specific Properties:<\/strong><\/p>\n<p>In your profile-specific YAML files, define the properties that should apply to that environment. For example, in <code>application-dev.yml<\/code>:<\/p>\n<pre><code class=\"language-yaml\">spring:\n  datasource:\n    url: jdbc:mysql:\/\/localhost:3306\/dev_db\n<\/code><\/pre>\n<p>And in <code>application-prod.yml<\/code>:<\/p>\n<pre><code class=\"language-yaml\">spring:\n  datasource:\n    url: jdbc:mysql:\/\/production-db:3306\/prod_db\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>Advanced Profile Handling<\/strong><\/p>\n<ul>\n<li>\n<p><strong>Profile Inheritance:<\/strong> Spring applies properties in a specific order.  <code>application.yml<\/code> provides defaults, overridden by profile-specific files.  This allows you to define common properties once and customize only what\u2019s needed.<\/p>\n<\/li>\n<li>\n<p><strong>Multiple Profiles:<\/strong> Activate multiple profiles simultaneously (e.g., <code>spring.profiles.active=dev,debug<\/code>).  Properties from both <code>application-dev.yml<\/code> and <code>application-debug.yml<\/code> will be applied.<\/p>\n<\/li>\n<li>\n<p><strong>Placeholders:<\/strong> Use placeholders (<code>${...}<\/code>) to keep your configuration flexible. You can define placeholders in <code>application.yml<\/code> and override them in profile-specific files.<\/p>\n<\/li>\n<\/ul>\n<p><strong>Example Scenario<\/strong><\/p>\n<p>Let\u2019s say you want to enable a \u201cmock\u201d data source for your tests.<\/p>\n<ol>\n<li>\n<p><strong>Create <code>application-test.yml<\/code>:<\/strong><\/p>\n<pre><code class=\"language-yaml\">spring:\n  profiles:\n    active: test \n  datasource:\n    url: jdbc:h2:mem:testdb\n    driver-class-name: org.h2.Driver\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Activate the \u201ctest\u201d profile when running your tests.<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>Now, your tests will use the in-memory H2 database instead of your development or production database.<\/p>\n<p><strong>Key Takeaways<\/strong><\/p>\n<ul>\n<li>Profiles provide a structured way to manage environment-specific configurations.<\/li>\n<li>Spring Cloud Config seamlessly integrates with Spring profiles, making it easy to externalize and manage these variations.<\/li>\n<li>By combining Spring Cloud Config with proper profile usage, you gain flexibility, reduce errors, and streamline your development process.<\/li>\n<\/ul>\n<p>This post provides a solid foundation for using multiple profiles with Spring Cloud Config. Experiment with different configurations and explore further options like profile-specific files within your application to tailor your setup to your needs.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":3751,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[433],"tags":[69,319],"series":[],"class_list":["post-3750","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring_config","tag-java-2","tag-spring"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/man-69283_1280-jpg.avif","jetpack-related-posts":[{"id":3744,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/3744\/","url_meta":{"origin":3750,"position":0},"title":"Spring Cloud Config: Choosing the Right Backend Storage","author":"Jeffery Miller","date":"December 23, 2025","format":false,"excerpt":"Spring Cloud Config offers a flexible way to manage your application\u2019s configuration. A crucial step is selecting the right backend to store your configuration data. Let\u2019s explore popular options, their pros and cons, configuration details, and the necessary dependencies for Maven and Gradle. 1. Git Pros: Version Control: Leverage Git\u2019s\u2026","rel":"","context":"In &quot;Spring Config&quot;","block_context":{"text":"Spring Config","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_config\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/woman-8696271_640.jpg?fit=438%2C640&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3747,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/secure-your-secrets-encrypting-values-with-spring-cloud-config\/","url_meta":{"origin":3750,"position":1},"title":"Secure Your Secrets: Encrypting Values with Spring Cloud Config","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the world of microservices, Spring Cloud Config provides a centralized way to manage externalized configurations for your applications. But what about sensitive data like database passwords or API keys? That\u2019s where encryption comes in. This blog post will guide you through the process of encrypting your sensitive values using\u2026","rel":"","context":"In &quot;Spring Config&quot;","block_context":{"text":"Spring Config","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_config\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 3x"},"classes":[]},{"id":3689,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/spring-cloud-config-encryption-securing-your-sensitive-data\/","url_meta":{"origin":3750,"position":2},"title":"Spring Cloud Config Encryption: Securing Your Sensitive Data","author":"Jeffery Miller","date":"November 18, 2025","format":false,"excerpt":"In the realm of modern application development, the security of sensitive data, such as database credentials, API keys, and third-party service configurations, is paramount. Spring Cloud Config, a powerful component of the Spring Cloud ecosystem, offers a streamlined approach to centralize and manage your application\u2019s configuration properties. However, storing sensitive\u2026","rel":"","context":"In &quot;Spring Config&quot;","block_context":{"text":"Spring Config","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_config\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/castle-3856_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/castle-3856_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/castle-3856_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/castle-3856_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/castle-3856_1280-jpg.avif 3x"},"classes":[]},{"id":3447,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/discovery-first-bootstrap\/","url_meta":{"origin":3750,"position":3},"title":"Discovery First Bootstrap","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the realm of microservices architecture, effective configuration management is crucial for ensuring the seamless operation and dynamic adaptability of distributed applications. Spring Cloud Config Server and Spring Cloud Discovery Server have emerged as powerful tools for addressing this challenge. While the default \"Config First\" mode offers a straightforward approach,\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3438,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/architecting-with-spring-and-spring-cloud\/","url_meta":{"origin":3750,"position":4},"title":"Architecting with Spring and Spring Cloud","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Building a Multi-Service Architecture with Spring 3.1.x and Spring Cloud: Unlocking the Power of Microservices In the ever-evolving landscape of software development, microservices have emerged as a powerful architectural paradigm, enabling organizations to build scalable, resilient, and agile applications. Spring, a widely adopted Java framework, provides a comprehensive suite of\u2026","rel":"","context":"In &quot;Spring&quot;","block_context":{"text":"Spring","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3395,"url":"https:\/\/www.mymiller.name\/wordpress\/springboot\/spring-profiles-and-yaml\/","url_meta":{"origin":3750,"position":5},"title":"Spring Profiles and YAML","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Configuration management is a critical aspect of building robust applications. Spring Boot simplifies configuration handling by supporting various file formats, including YAML. YAML (YAML Ain't Markup Language) offers a human-readable and concise syntax, making it an excellent choice for configuring Spring Boot applications. In this article, we will explore how\u2026","rel":"","context":"In &quot;Springboot&quot;","block_context":{"text":"Springboot","link":"https:\/\/www.mymiller.name\/wordpress\/category\/springboot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/icon-gc4bfcbaa4_640.png?fit=640%2C640&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/icon-gc4bfcbaa4_640.png?fit=640%2C640&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/icon-gc4bfcbaa4_640.png?fit=640%2C640&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3750"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3750\/revisions"}],"predecessor-version":[{"id":3752,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3750\/revisions\/3752"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3751"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3750"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}