{"id":3395,"date":"2025-12-24T10:01:09","date_gmt":"2025-12-24T15:01:09","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3395"},"modified":"2025-12-24T10:01:09","modified_gmt":"2025-12-24T15:01:09","slug":"spring-profiles-and-yaml","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/springboot\/spring-profiles-and-yaml\/","title":{"rendered":"Spring Profiles and YAML"},"content":{"rendered":"<p>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&#8217;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 to leverage YAML property files in Spring Boot, providing practical examples along the way.<\/p>\n<ol>\n<li>Understanding YAML Property Files:<br \/>\nYAML property files allow you to define application properties using a structured and readable format. The YAML syntax consists of key-value pairs, nested data structures, and lists, making it flexible for representing complex configurations.<\/li>\n<li>Creating YAML Property Files:<br \/>\nTo start using YAML property files in your Spring Boot application, create a new file in the <code>src\/main\/resources<\/code> directory and name it <code>application.yml<\/code> or <code>application.yaml<\/code>. Spring Boot automatically picks up this file as the default configuration source.<\/li>\n<li>Basic Property Configuration:<br \/>\nYAML property files use indentation and colons to define properties and their values. Here&#8217;s an example of a basic YAML property file:<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">server:\n  port: 8080\n  context-path: \/myapp\n\ndatabase:\n  url: jdbc:mysql:\/\/localhost:3306\/mydb\n  username: myuser\n  password: mypassword\n<\/code><\/pre>\n<ol start=\"4\">\n<li>Accessing YAML Properties:<br \/>\nTo access YAML properties in your Spring Boot application, you can use the <code>@Value<\/code> annotation or <code>@ConfigurationProperties<\/code> annotation.<\/li>\n<\/ol>\n<p>a. Using the @Value Annotation:<\/p>\n<pre><code class=\"language-java\">@Value(\"${server.port}\")\nprivate int serverPort;\n\n@Value(\"${database.url}\")\nprivate String databaseUrl;\n<\/code><\/pre>\n<p>b. Using the @ConfigurationProperties Annotation:<\/p>\n<pre><code class=\"language-java\">@ConfigurationProperties(prefix = \"server\")\npublic class ServerProperties {\n    private int port;\n    private String contextPath;\n\n    \/\/ Getters and setters\n}\n<\/code><\/pre>\n<ol start=\"5\">\n<li>Nested Properties:<br \/>\nYAML property files support nested structures, allowing you to organize your configurations in a hierarchical manner. Here&#8217;s an example:<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">app:\n  name: MyApp\n  version: 1.0.0\n  author:\n    name: John Doe\n    email: johndoe@example.com\n<\/code><\/pre>\n<p>To access nested properties, you can use dot notation or the <code>@ConfigurationProperties<\/code> annotation with nested classes.<\/p>\n<ol start=\"6\">\n<li>Lists and Arrays:<br \/>\nYAML property files can handle lists and arrays efficiently. Here&#8217;s an example:<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">fruits:\n  - apple\n  - banana\n  - orange\n<\/code><\/pre>\n<p>To access a list or array property, you can use the <code>@Value<\/code> annotation with the <code>List<\/code> or <code>String[]<\/code> type, or the <code>@ConfigurationProperties<\/code> annotation with a <code>List<\/code> or <code>Array<\/code> field.<\/p>\n<ol start=\"7\">\n<li>Profiles in YAML Property Files:<br \/>\nYAML property files support profiles, allowing you to define different configurations for different environments. Create separate YAML files for each profile, such as <code>application-dev.yml<\/code> and <code>application-prod.yml<\/code>, and specify the active profile using the <code>spring.profiles.active<\/code> property in your <code>application.yml<\/code> file.<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">spring:\n  profiles:\n    active: dev\n<\/code><\/pre>\n<ol start=\"8\">\n<li>Externalizing YAML Property Files:<br \/>\nYou can externalize YAML property files by specifying the file location using the <code>spring.config.name<\/code> and <code>spring.config.location<\/code> properties.<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">java -jar myapp.jar --spring.config.name=myapp --spring.config.location=file:\/path\/to\/config\/\n<\/code><\/pre>\n<h2>Multiple Profiles in a Single File in Spring Boot<\/h2>\n<p>Managing application configurations efficiently is crucial for building flexible and maintainable systems. Spring Boot provides robust support for configuration management using YAML property files. In this article, we will explore how to utilize YAML property files with multiple profiles defined within a single file in Spring Boot, providing practical examples and a step-by-step guide.<\/p>\n<ol>\n<li>Understanding YAML Property Files and Multiple Profiles:<br \/>\nYAML property files offer a clean and readable format for configuring Spring Boot applications. Multiple profiles allow you to define different sets of properties for various environments or deployment scenarios. By combining these features within a single YAML file, you can streamline configuration management and avoid maintaining separate files for each profile.<\/li>\n<li>Creating a YAML Property File with Multiple Profiles:<br \/>\nTo begin, create a YAML property file, such as <code>application.yml<\/code> or <code>application.yaml<\/code>, in the <code>src\/main\/resources<\/code> directory. This single file will contain the configurations for all the profiles you want to define.<\/li>\n<li>Defining Profile-Specific Properties:<br \/>\nTo specify profile-specific properties within the single YAML property file, utilize YAML&#8217;s syntax for nesting and separating profiles. Here&#8217;s an example of how to define different database configurations for the <code>dev<\/code> and <code>prod<\/code> profiles:<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">spring:\n  profiles:\n    active: dev\n\n---\n\nspring:\n  profiles: dev\n  database:\n    url: jdbc:mysql:\/\/localhost:3306\/devdb\n    username: devuser\n    password: devpassword\n\n---\n\nspring:\n  profiles: prod\n  database:\n    url: jdbc:mysql:\/\/localhost:3306\/proddb\n    username: produser\n    password: prodpassword\n<\/code><\/pre>\n<p>In the above example, the <code>spring.profiles.active<\/code> property is set to <code>dev<\/code>, indicating that the <code>dev<\/code> profile is active by default. Each profile-specific configuration is encapsulated within <code>---<\/code> separators.<\/p>\n<ol start=\"4\">\n<li>Accessing Profile-Specific Properties:<br \/>\nTo access the profile-specific properties in your Spring Boot application, you can use the <code>@Value<\/code> annotation or the <code>@ConfigurationProperties<\/code> annotation.<\/li>\n<\/ol>\n<p>a. Using the @Value Annotation:<\/p>\n<pre><code class=\"language-java\">@Value(\"${spring.database.url}\")\nprivate String databaseUrl;\n\n@Value(\"${spring.database.username}\")\nprivate String databaseUsername;\n\n@Value(\"${spring.database.password}\")\nprivate String databasePassword;\n<\/code><\/pre>\n<p>b. Using the @ConfigurationProperties Annotation:<\/p>\n<pre><code class=\"language-java\">@ConfigurationProperties(prefix = \"spring.database\")\npublic class DatabaseProperties {\n    private String url;\n    private String username;\n    private String password;\n\n    \/\/ Getters and setters\n}\n<\/code><\/pre>\n<ol start=\"5\">\n<li>Switching between Profiles:<br \/>\nTo switch between different profiles defined within the same YAML property file, you can modify the <code>spring.profiles.active<\/code> property value in your application.<\/li>\n<\/ol>\n<ul>\n<li>By setting the property in the <code>application.properties<\/code> file:<\/li>\n<\/ul>\n<pre><code class=\"language-properties\">spring.profiles.active=prod\n<\/code><\/pre>\n<ul>\n<li>By passing the active profile as a command-line argument:<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">java -jar your-app.jar --spring.profiles.active=prod\n<\/code><\/pre>\n<ul>\n<li>By setting the <code>SPRING_PROFILES_ACTIVE<\/code> environment variable:<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">export SPRING_PROFILES_ACTIVE=prod\n<\/code><\/pre>\n<ol start=\"6\">\n<li>Default Properties:<br \/>\nIn addition to profile-specific properties, you can define default properties within the same YAML file. These default properties will be used when no profile-specific properties are available.<\/li>\n<li>Property Precedence:<br \/>\nSpring Boot follows a specific order of precedence when resolving properties, considering both profile-specific and default properties:<\/li>\n<li>Profile-specific properties (highest precedence)<\/li>\n<li>Default properties<\/li>\n<li>Command-line arguments<\/li>\n<li>Environment variables<\/li>\n<li>System properties (lowest precedence)<\/li>\n<\/ol>\n<p>Conclusion:<br \/>\nUtilizing a single YAML property file with multiple profiles simplifies configuration management in Spring Boot applications<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 to leverage YAML property files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3404,"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":[448],"tags":[],"series":[397],"class_list":["post-3395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-springboot","series-spring"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/icon-gc4bfcbaa4_640.png?fit=640%2C640&ssl=1","jetpack-related-posts":[{"id":3750,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/mastering-multi-profile-environments-with-spring-cloud-config\/","url_meta":{"origin":3395,"position":0},"title":"Mastering Multi-Profile Environments with Spring Cloud Config","author":"Jeffery Miller","date":"December 19, 2025","format":false,"excerpt":"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. Why Use Multiple Profiles? Imagine your application needs different settings for\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\/man-69283_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/man-69283_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/man-69283_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/man-69283_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/man-69283_1280-jpg.avif 3x"},"classes":[]},{"id":3671,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/spring-cloud-data-flow-orchestrating-machine-learning-pipelines\/","url_meta":{"origin":3395,"position":1},"title":"Spring Cloud Data Flow: Orchestrating Machine Learning Pipelines","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the dynamic world of machine learning, the journey from raw data to a deployed model involves a series of intricate steps. Spring Cloud Data Flow (SCDF) emerges as a powerful ally, offering a comprehensive platform to streamline and manage these complex data pipelines. In this guide, we\u2019ll delve into\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 3x"},"classes":[]},{"id":3834,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_rest\/documenting-your-datas-reach-generating-api-docs-for-spring-data-rest\/","url_meta":{"origin":3395,"position":2},"title":"Documenting Your Data&#8217;s Reach: Generating API Docs for Spring Data REST","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Data REST is a fantastic tool for rapidly exposing your JPA entities as hypermedia-driven REST APIs. However, even the most intuitive APIs benefit from clear and comprehensive documentation. While HATEOAS provides discoverability at runtime, static documentation offers a bird\u2019s-eye view, making it easier for developers to understand the API\u2019s\u2026","rel":"","context":"In &quot;Spring Rest&quot;","block_context":{"text":"Spring Rest","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_rest\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_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":3395,"position":3},"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":3890,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_messaging\/spring-cloud-stream\/","url_meta":{"origin":3395,"position":4},"title":"Spring Cloud Stream","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Cloud Stream is a framework for building highly scalable, event-driven microservices that are connected by a shared messaging system. In simple terms, it's a powerful tool that takes away the complexity of communicating with message brokers like RabbitMQ or Apache Kafka, allowing you to focus purely on your application's\u2026","rel":"","context":"In &quot;Spring Messaging&quot;","block_context":{"text":"Spring Messaging","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_messaging\/"},"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":3780,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-jess-with-a-spring-boot-microservice\/","url_meta":{"origin":3395,"position":5},"title":"Integrating Jess with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"This post explores how to integrate the Jess rule engine with your Spring Boot microservice. We\u2019ll cover adding the necessary dependency, configuring Jess, and creating a service to utilize it. 1. Project Setup and Dependency Begin by creating a Spring Boot project. Then, add the Jess dependency to your pom.xml\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3395","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=3395"}],"version-history":[{"count":2,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3395\/revisions"}],"predecessor-version":[{"id":3405,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3395\/revisions\/3405"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3404"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3395"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}