Hi, I have a Spring Boot application (running spring-boot-starter 1.1.6.RELEASE) with an external application.yml configuration file. I build and run the application as a jar without issues if the config file is in the same directory as the jar or in the subdirectory config/ as the default settings specify. But if I place the config file in a subdirectory called conf and try to run the jar with the spring.config.location file path, it doesn't work (as in, the config file is not picked up):

java -jar sitemap-generator.jar --spring.config.location=file:conf/

I've also tried renaming the configuration file to e.g. test.yml (while keeping it in the same directory as the jar) and tried using spring.config.name with the same results:

java -jar sitemap-generator.jar --spring.config.name=test

At first, I thought that I had just misunderstood the syntax of the spring.config.location property but I've tried every possible variation of specifying a file path (relative or absolute, with or without slashes, with or without "file:") and nothing has worked. Am I missing something obvious here?

Showing simplified versions of my Config classes and main Application class below:

    @Configuration
    public class SpringConfig {

    @Bean
    Settings settings() {
        return new Settings();
    }
        ....

And the settings file:

@Component
@ConfigurationProperties(ignoreUnknownFields = false)
public class Settings {
    private String productBaseUrl;

    public String getProductBaseUrl() {
        return productBaseUrl;
    }

    public void setProductBaseUrl(String productBaseUrl) {
        this.productBaseUrl = productBaseUrl;
    }

With the main file with these annotations:

@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(UpdateTask.class);
    }
}

Comment From: snicoll

Can you try with file:./conf/ instead?

Comment From: dsyer

Does it work with -Dspring.config.location=... (before the jar file obviously)?

Comment From: dsyer

Ah, I just read your main method. You aren't passing the args on to the SpringApplication. Should be

@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(UpdateTask.class, args);
    }
}

N.B. I copied that blindly and I have no idea why UpdateTask is the right source file.

Comment From: awikell

Thank you, passing the args to the run()-method solved it.

Comment From: btiernay

On this note, is it possible to support conf/ as one of the conventional configuration source locations? It seems to be another common practice to place configuration files in such location.

Comment From: wilkinsona

@btiernay We can certainly consider it, but I don't think that discussion belongs in this issue. Can you please open a separate issue so that we don't lose track?

Comment From: vitali1980

Discussing implementation and support. having same issue. if spring.config.name provided and not able to read - WARNING OR ERROR MESSAGE should be produced in log. Every single day - fighting with spring staff. Annoying

Comment From: wilkinsona

@vitali1980 This issue is closed and has been for over 3 years. If you have a constructive suggestion for an enhancement, please open a new issue. However, please note that I don't think we can implement what I understand you are asking for. Even if spring.config.name has been set, there's no requirement for an application to have any configuration files. For application's that don't, any warning or error message that was logged would be annoying and misleading.

Comment From: medzeus2

I have the same problem. But when I use -Dspring.config.location, It works fine.When use --spring.config.location=file:./application.yml, the yml cannot override the application.properties config, but the file:./application.properties can.

Something i get wrong, the yml file format is not correct , it work find on spring boot 1.5.9.RELEASE

Comment From: wilkinsona

@medzeus2 This issue is closed and was due to user error. Please read the rest of the comments on the issue, particularly this one. If that doesn't help please open a new issue with a small sample that reproduces the problem.

Comment From: medzeus2

@wilkinsona Sorry it is my fault.

Comment From: shouldnotappearcalm

you should add args in main method SpringApplication.run(UpdateTask.class, args);

Comment From: SureshyYadav

@wilkinsona , @awikell , @dsyer i don't want use after build the jar file, i want to use while developing the code. can you provide an example on spring.config.location.

spring.config.name=spring spring.config.location=classpath:/config/ i am trying to use, but it is not working.

Comment From: wilkinsona

@SureshyYadav You could set spring.config.location and spring.config.name as default properties on SpringApplicationBuilder in your main method. If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.