繁体   English   中英

spring boot将另一个属性文件添加到环境中

[英]spring boot adding another properties file to the environment

我想知道除了application.properties文件之外是否可以将另一个属性文件添加到环境路径中。 如果是这样,您如何指定新路径? 因此,您可以使用Autowired Environment变量访问属性。 目前在我的java项目中,默认属性文件application.properties具有路径/soctrav/src.main.resources/application.properties

您可以使用命令行参数指定其他属性文件:

java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

看一下Application属性文件Spring Boot doc章节

如果你想在没有命令行参数的情况下这样做,这就可以了。

@SpringBootApplication
@PropertySources({
        @PropertySource("classpath:application.properties"),
        @PropertySource("classpath:anotherbunchof.properties")
})
public class YourApplication{

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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