@Value注解会在哪里查找数值呢?

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

where does spring look for values with the @Value annotation

问题

在Java/Spring中,当您使用@Value注解将值插入字段时,应用程序会从何处寻找这些值?我已经阅读过,我不断看到它在寻找一个“属性文件”,但这个文件是否需要具有特定的名称/格式,或者这个文件需要放在某个特定的目录中?

英文:

In java/spring, when you use the @Value annotation to insert values into a field, where exactly does the application look for these values? I have read up and I keep seeing that it looks for a "properties file" but is there a specific name/format this file needs to have, or a certain directory this file needs to be in?

答案1

得分: 1

如果您没有提供任何特定的路径,则会使用默认路径:

\src\main\resources\application.properties

您还可以指定路径:

@propertySource("file:properties/application.properties")

这里的 properties 文件夹与 src 文件夹在同一级别。您可以将属性文件放在任何地方。

希望这能起作用!

英文:

If you don't give any specific path thn it will use default path :

\src\main\resources\application.properties

You can also give specific path :

@propertySource("file:properties/application.properties")

Here properties folder is on same level of src folder. You can put your property file anywhere.

Hope this will work!

huangapple
  • 本文由 发表于 2020年4月8日 09:42:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/61092088.html
匿名

发表评论

匿名网友

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

确定