2017-07-16 35 views
0

当我从--spring.config.location=another.properties的命令行运行Spring引导应用程序时,another.properties中的值将被覆盖application.properties中的值?使用spring.config.location运行Spring替代值为application.properties的.jar文件?

例如:

如果有一个值spring.datasource.urlapplication.properties,但不是在application.properties。所以该值取自another.properties或未定义?

+0

你试过了吗? – chrylis

+0

我试过了。如果值不在another.properties中,则应用程序使用application.properties中的值。看来application.properties是默认的。 – ADN

回答

0

它取代。
documentation状态:

如果你不喜欢application.properties作为配置文件 名,你可以通过指定spring.config.name 环境属性切换到另一个。您还可以使用spring.config.location环境属性(目录位置或文件路径的逗号分隔列表 )引用显式位置。

现在,没有人阻止你在spring.config.location值声明多个属性:

$ java -jar myproject.jar --spring.config.location=classpath:/application.properties,classpath:/another.properties 

这样,another.properties覆盖性能也存在于application.properties