gpt4 book ai didi

spring-boot - 使用外部属性文件

转载 作者:行者123 更新时间:2023-11-28 23:14:40 25 4
gpt4 key购买 nike

我希望在 tomcat 上部署 war 文件后在运行时传递变量 ..我如何使用 application.properties whcih 与另一个属性文件 ex 一起在 classplath 中。位于特定目录的 abcd.properties..我基本上是在寻找设置额外的类路径并从该路径中的属性文件读取值以及 war 部署的默认类路径位置。

我正在使用 Spring boot。其中一种方法是将所有属性传递到数据库端,但我正在寻找基于文件的方法,即基于属性的锻炼。(在同一个 tomcat 实例上有多个应用程序。)

最佳答案

  1. Spring Boot 应用 --> 运行方式 --> 运行配置。现在在 VM 参数中添加 Dproperties.location="Path of the properties"。
  2. 现在,在您的 Spring Boot 应用程序中,在类声明上方使用注释 @PropertySource("file:${properties.location}/propertiesfileName.properties")。
  3. 您类(class)中的 Autowiring 环境。使用 env.getProperty("propertyname")。
  4. 您可以像往常一样使用@Value 注释访问application.properties 中的值。希望这会有所帮助。

关于spring-boot - 使用外部属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51846358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com