Spring Boot在云环境中未加载应用程序属性。

huangapple go评论69阅读模式
英文:

Springboot is not loading application properties in cloud environment

问题

我遇到了一个奇怪的情况,我目前正在升级我的应用程序,使用新的JAR文件。但是在更新了新的JAR文件之后,我的云环境部署停止工作了。在我的本地环境中,它运行得非常正常。

这个JAR文件有它自己的Spring Boot配置,但我相信它不应该影响我的更改。

当我打印所有的环境变量时,我注意到我的application.yml文件没有被加载,这导致了这个问题,但我不知道为什么?有没有人遇到过类似的情况。

升级之前:Spring Boot属性源:

OriginTrackedMapPropertySource {name='Config resource 'file [/etc/config/application.yaml]' via location 'optional:file:/etc/config/application.yaml''}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/old-defaults.yml]'}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/old-defaults.yml] (document #0)'}

升级后:Spring Boot属性源:

OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/new-defaults.yml]#default (document #1)'}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/new-defaults.yml] (document #0)'}

我注意到升级后,OriginTrackedMapPropertySource中的'config resource'已经消失。
此外,我观察到之前显示的Spring活动配置现在为空。

我正在使用Spring Boot 2.7.4和Java 17版本。

英文:

I have a weird case, I am currently working on upgrading my application with new jars. However after updating with New Jars. My deployment in cloud environment stopped working. It works absolutely fine in my local.

This jar has its own springboot configurations but I believe it should not affect my changes.

When I print all the environment variables, I observed that my application.yml is not getting loaded which is causing this issue but I have no idea why ? Has one one come across similar situation.

Before upgrade: Springboot property source:

OriginTrackedMapPropertySource {name='Config resource 'file [/etc/config/application.yaml]' via location 'optional:file:/etc/config/application.yaml''}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/old-defaults.yml]'}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/old-defaults.yml] (document #0)'}

After upgrade: Springboot property source:


OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/new-defaults.yml]#default (document #1)'}
OriginTrackedMapPropertySource {name='appDefaultConfig [classpath:/new-defaults.yml] (document #0)'}

I see that 'config resource ' in OriginTrackedMapPropertySource is missing after upgrade.
Also, I observed that spring active profile which was displaying earlier is now showing empty.

I am using spring boot 2.7.4 Java 17 version.

答案1

得分: 0

问题似乎出在我设置Maven命令中的Spring配置文件的方式上。之前的设置是:

-Dspring.config.location=optional:classpath:/,optional:file:/etc/config/application.yaml

我将其更改为:

-Dspring.config.location=file:/etc/config/application.yaml

然后它开始正常工作。然而,我无法弄清楚背后的原因。

英文:

Well, The issue seem to be with the way I set spring profile in my mvn command. Previously it was set to -Dspring.config.location=optional:classpath:/,optional:file:/etc/config/application.yaml

I changed to
-Dspring.config.location=file:/etc/config/application.yaml and it started working. However, I could not figure out the reason behind it.

huangapple
  • 本文由 发表于 2023年7月17日 20:34:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704506.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定