简体   繁体   English

Spring 引导附加属性

[英]Spring Boot additional properties

I am using Spring Boot for creating microservices.我正在使用 Spring Boot 来创建微服务。 By default it uses application.properties for configurations.默认情况下,它使用application.properties进行配置。 But I have a requirement to use another property file which is outside of jar file.但我需要使用 jar 文件之外的另一个属性文件。 I tried following options in eclipse JVM arguments while running bootRun from Gradle but still it didn't work.我在 eclipse JVM bootRun从 Z7B5CC4FB56E11DC7520F716EC17DZ 运行 bootRun 时尝试了以下选项,但它仍然没有工作。

-Dspring.config.location=c:/another.properties  
-Dspring.config.additional-location=c:/another.properties
-Dspring.config.import=c:/another.properties

I also tried adding the above properties inside application.properties but still @Value annotation added in controller class which refers a property from c:/another.properties is not getting injected.我还尝试在 application.properties 中添加上述属性,但仍然在 controller class 中添加了@Value注释,它引用了来自c:/another.properties的属性。

The spring.config.additional-location should be a folder and the value should end with / spring.config.additional-location应该是一个文件夹,值应该以/结尾

From the documentation:从文档中:

You can provide default values for your application in application.properties (or whatever other basename you choose with spring.config.name) in one of the default locations.您可以在默认位置之一的 application.properties(或您使用 spring.config.name 选择的任何其他基本名称)中为您的应用程序提供默认值。 These default values can then be overridden at runtime with a different file located in one of the custom locations.然后可以在运行时使用位于自定义位置之一的不同文件覆盖这些默认值。

REF: 24.3 Application Property Files REF: 24.3 应用程序属性文件

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

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