简体   繁体   中英

where does spring look for values with the @Value annotation

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM