CodexBloom - Programming Q&A Platform

Spring Boot Application scenarios to Load Properties from YAML File with Profiles

👀 Views: 61 đŸ’Ŧ Answers: 1 📅 Created: 2025-08-26
spring-boot yaml configuration profiles Java

I'm updating my dependencies and I'm confused about I'm currently working with an scenario with my Spring Boot application (version 2.5.4) where it fails to load properties from a YAML configuration file when using specific profiles... I have the following setup in my `application.yml`: ```yaml spring: profiles: active: dev --- spring: profiles: dev datasource: url: jdbc:mysql://localhost:3306/dev_db username: dev_user password: dev_password --- spring: profiles: prod datasource: url: jdbc:mysql://localhost:3306/prod_db username: prod_user password: prod_password ``` When I run my application with the command `mvn spring-boot:run`, I expect it to load the `dev` profile and connect to the `dev_db`. However, I'm receiving the following behavior in the logs: ``` Failed to bind properties under 'datasource' to DataSourceProperties: Property 'url' is required; it must not be null ``` I have confirmed that the `application.yml` file is located in the `src/main/resources` directory and that the indentation is correct (I double-checked). I also tried explicitly setting the profile via command line using `--spring.profiles.active=dev`, but the scenario continues. Additionally, I verified that there are no other configurations in `application.properties` that might be overriding these settings. How can I ensure that my Spring Boot application correctly loads the YAML properties based on the active profile? Any insights on what might be going wrong here would be greatly appreciated. Am I missing something obvious? I've been using Java for about a year now.