How do I configure Spring Boot to use
application-local.properties
instead of
application.properties
working locally?
In your case, it looks like you want to have a local
profile. In this case you could do the following, which would load application-local.properties
if it is in your resources directory:
tasks.named<BootRun>("bootRun") {
systemProperty(
"spring.profiles.active",
"local"
)
}
Using this method, though, you have to keep ALL of your properties in BOTH application.properties
and application-local.properties
.
A better approach is to keep all of your defaults in application.properties
and only keep your override properties in application-local.properties
. AND not keep application-local.properties
bundled with your application, which could lead to accidentally enabling the local
profile in production.
To do this, put application-local.properties
in your project root or in a subdirectory there and do this:
tasks.named<BootRun>("bootRun") {
systemProperty(
"spring.config.import",
"file:application-local.properties"
)
}
Details about how configuration files are loaded and the properties that can be set related to these can be found here: