英文:
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论