[英]Spring Boot YAML Config w/ unique file name
I am trying to read in a simple yml file for a Spring Boot application located at resources/wtf.yml. 我试图在一个简单的yml文件中读取位于resources / wtf.yml的Spring Boot应用程序。 The following application works if the default application.yml filename is used, but not if I change the filename.
如果使用默认的application.yml文件名,则以下应用程序有效,但如果我更改文件名则不行。 Anyone know why this doesn't work?
任何人都知道为什么这不起作用?
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引导指南中所述的spring.config.name
或spring.config.location
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.