CodexBloom - Programming Q&A Platform

Spring Boot application scenarios to load configuration properties from external YAML file

๐Ÿ‘€ Views: 19 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-15
spring-boot yaml configuration Java

I'm trying to figure out I'm experiencing an scenario where my Spring Boot application is not loading configuration properties from an external YAML file... I've set up my application with a typical structure, and I expected the properties to be read from an `application.yml` located in the same directory as my JAR file. However, when I run the application, I'm seeing this behavior: ``` Failed to load property source from location 'file:./application.yml' ``` I've verified that the `application.yml` file exists and is readable. My Spring Boot version is `2.5.4`, and I'm using Maven for dependency management. Hereโ€™s how Iโ€™m running the application: ``` mvn spring-boot:run -Dspring-boot.run.arguments="--spring.config.location=file:./application.yml" ``` I tried hardcoding a property inside the `application.yml`, such as: ```yaml server: port: 8080 ``` But the application starts up without picking up this configuration. I've also tried placing the YAML file in `src/main/resources/` and running the app, but that doesn't seem to help either. I suspect thereโ€™s an scenario with the way I'm referencing the external configuration, but I canโ€™t quite pinpoint it. Can someone provide guidance on how to correctly load an external YAML configuration file in a Spring Boot application? Any help would be much appreciated! Any ideas what could be causing this?