Home >Java >javaTutorial >How Can I Override Spring Boot\'s Default Configuration Files with External Properties?
Spring Boot allows for the loading of multiple property files from the classpath. By default, properties from the /src/main/resources folder are loaded. However, it is also possible to specify additional external configuration files to override the default ones.
Spring Boot loads properties in a specific order:
To load external configuration files, use the spring.config.location property, which accepts a comma-separated list of property files or file locations. For example:
-Dspring.config.location=/config/application.properties
By default, external configuration files are added to the list of configuration sources. However, if you want to override the default files, use the spring.config.additional-location property, which only appends the specified locations. For example:
-Dspring.config.location=/config/job1.properties -Dspring.config.additional-location=/config/job2.properties
In this case, the job1.properties file will override the default properties, while job2.properties will add additional properties.
In Spring Boot 2.x, the spring.config.location property now overrides the default instead of adding to it. Therefore, use spring.config.additional-location to preserve the default properties.
The above is the detailed content of How Can I Override Spring Boot's Default Configuration Files with External Properties?. For more information, please follow other related articles on the PHP Chinese website!