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?
Asked
Active
Viewed 915 times
0
-
Does this help? [Spring @Value is not resolving to value from property file](https://stackoverflow.com/questions/15937592/spring-value-is-not-resolving-to-value-from-property-file) – Abra Apr 08 '20 at 01:57
-
What version of Spring are you using? Have you tried adding a key-value in `\src\main\resources\application.properties` and then reading it in your class? Something like `app.db.name=ABC` in `application.properties` and then reading it in your class using `@Value(value = "${app.db.name}") private transient String dbName;`? – GopherGopher Apr 08 '20 at 02:00
-
1Are you using Boot? (You should if you can.) https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties – chrylis -cautiouslyoptimistic- Apr 08 '20 at 02:12
1 Answers
1
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!

Birju B
- 140
- 1
- 5
-
in the first path you gave, will that work if the file is application.yml? (in the resources folder) – kaido Apr 09 '20 at 00:25