我有spring-boot项目。当我在resources目录中使用application.yml时,它运行良好。我正试图将application.yml移到resources目录之外,但它已经不起作用了。我很好奇,只是想知道,有什么办法让它发挥作用吗?
您可以使用环境属性spring.config.location
指向您的替代路径,例如,按如下方式启动应用程序:
java -jar app.jar --spring.config.location=/some/path/application.yml
还请参阅";外部应用程序属性";在官方的Spring Boot文档中。
您可以使用@PropertySource注释从任何位置加载
@Configuration
@PropertySource(value = "classpath:application.properties")
public class ApplicationConfig {
// more configuration ...
}
//添加应用程序的路径.yml