简体   繁体   中英

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM