Java 带唯一文件名的Spring Boot YAML配置

Java 带唯一文件名的Spring Boot YAML配置,java,spring,spring-boot,Java,Spring,Spring Boot,我试图为位于resources/wtf.yml的Spring引导应用程序读入一个简单的yml文件。如果使用默认的application.yml文件名,则以下应用程序可以工作,但如果我更改了文件名,则无法工作。有人知道为什么这样不行吗 import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframew

我试图为位于resources/wtf.yml的Spring引导应用程序读入一个简单的yml文件。如果使用默认的application.yml文件名,则以下应用程序可以工作,但如果我更改了文件名,则无法工作。有人知道为什么这样不行吗

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import javax.annotation.PostConstruct;

@EnableConfigurationProperties
@SpringBootApplication
@ConfigurationProperties(locations = {"wtf.yml"}) //classpath:wtf.yml
public class SomeApp {

  public static void main(final String[] args) {
    SpringApplication.run(SomeApp.class, args);
  }

  @PostConstruct
  public void init() {
    System.out.println(readTimeout);
  }

  @Value("${readTimeout}")
  public int readTimeout;
}

您可以使用中所述的
spring.config.name
spring.config.location
属性。

您可以使用中所述的
spring.config.name
spring.config.location
属性。

如果能够设置属性文件位置而不提供命令行属性或作为另一个yaml文件中的参数。如果能够在不提供命令行属性或作为另一个yaml文件中的参数的情况下设置属性文件位置,那就太好了。