程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Spring Boot spring.config.additional-location 作为相对路径大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Spring Boot spring.config.additional-LOCATIOn 作为相对路径?

开发过程中遇到Spring Boot spring.config.additional-LOCATIOn 作为相对路径的问题如何解决?下面主要结合日常开发的经验,给出你关于Spring Boot spring.config.additional-LOCATIOn 作为相对路径的解决方法建议,希望对你解决Spring Boot spring.config.additional-LOCATIOn 作为相对路径有所启发或帮助;

我有一个具有这种结构的 Spring Boot 项目:

@H_618_4@- /my-config - production-setTings.yml - local-setTings.yml - /src - /main - /java - (the usual Java stuff) - /resources - application.yml

这是我的application.yml

@H_618_4@@H_596_5@my.personal.value: ${MY_PLACEHolDER}

我使用在 local-setTings.yml 中定义的占位符:

@H_618_4@@H_596_5@mY_PLACEHolDER: something

谁能告诉我如何使用带有文件 spring.config.additional-LOCATIOn 相对路径的 local-setTings.yml,以便可以解析占位符。

谢谢。

解决方法

您可以使用 @Propertysource("file:./my-config/local-setTings.yml") 测试相对路径以查看 @H_596_5@my.personal.value 是否已加载。

@H_618_4@@Configuration // If the relative path is valid,just comment the Propertysource. // @Propertysource("file:./my-config/local-setTings.yml") public class MyPersonConfig { @Value("${my.personal.value}") private String value; @PostConstruct void run() { System.out.println(value); } }

如果它工作正常,您可以设置 JVM 选项并启动您的 jar。更改 local-setTings.ymlproduction-setTings.yml 以进行测试。

@H_618_4@java -jar -Dspring.config.additional-LOCATIOn=file:./my-config/local-setTings.yml build/libs/your.jar

完整代码为here。

大佬总结

以上是大佬教程为你收集整理的Spring Boot spring.config.additional-location 作为相对路径全部内容,希望文章能够帮你解决Spring Boot spring.config.additional-location 作为相对路径所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。