jcgarcia
jcgarcia

Reputation: 3882

Custom config location and config name on Spring Boot

I'm trying to customize Spring Boot config location and config name using spring.config.name and spring.config.location properties as I've saw on Spring Boot reference guide

I've created an Spring Boot basic application to test it.

I'm able to customize it using OS environment variable like export SPRING_CONFIG_NAME=custom and/or export SPRING_CONFIG_LOCATION=classpath:/custom/location.properties. That works fine!

But I want to know, if it's possible to define spring.config.name=custom on default application.properties and then create a custom.properties file where I'll be able to define all application configuration properties.

I've checked it, and seems that it's not working defining spring.config.name property on application.properties... but I want to know if this is a valid way to do it before to create an issue on gitHub.

Regards,

Upvotes: 4

Views: 15247

Answers (1)

Guy Bouallet
Guy Bouallet

Reputation: 2125

From spring documentation:

spring.config.location environment property (comma-separated list of directory locations, or file paths)

Moreover, code in ConfigFileApplicationListener shows that if there if no environment property, processing fallbacks to:

DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";

And for the name:

DEFAULT_NAMES = "application";

So it is normal that what you are doing is not working.

Upvotes: 7

Related Questions