@Value注解在Spring中用于在运行时评估变量的值。

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

Can you evaluate what a variable would be with @Value annotation in spring at runtime

问题

我在使用@Value注解时遇到了问题,我想知道在调试时是否有办法检查@Value注解的值。例如,我想在我的代码中设置断点并评估以下内容:

@Value("${myString}")
String x;

或者如果我想检查Spring配置文件的激活的profile,我可以评估以下内容:

@Value("${spring.profiles.active}")
String springProfile;

然而,对于这些情况,我只看到了null值。

英文:

I am having issues using my properties with @Value annotation and I am wondering is there a way when debugging to check the value of an @Value annotation. For example I would stop at a breakpoint in my code and evaluate

@Value("${myString}")
String x;

or say if i wanted to check the spring profile i would evaluate

@Value("${spring.profiles.active}")
String springProfile;

I do only see null values for these though?

答案1

得分: 0

弹簧的值将在调用代码之前进行初始化,因此我们将能够在运行时评估所有弹簧属性。

英文:

The spring values will be initialized before we call the code so we will be able to evaluate all spring properties at run time.

huangapple
  • 本文由 发表于 2020年7月22日 18:50:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63032485.html
匿名

发表评论

匿名网友

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

确定