In Spring property (or yaml) files we can reference other properties using the ${..} syntax.
For example:
1 2 3 | external.host=https://api.external.comexternal.productService=${external.host}/product-serviceexternal.orderService=${external.host}/order-service |
If we now access the external.productService property (e.g. by using the @Value annotation) we will get the value https://api.external.com/product-service.
For example:
1 2 | @Value("${external.productService}") |
This way we can avoid duplication of commonly used values in property and yaml files.
Published on Java Code Geeks with permission by Michael Scharhag, partner at our JCG program. See the original article here: Quick tip: Referencing other Properties in Spring Opinions expressed by Java Code Geeks contributors are their own. |
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Thank you!
We will contact you soon.
Tags
Spring
π Photo of Michael Scharhag
Michael ScharhagSeptember 15th, 2020Last Updated: September 11th, 2020
Michael ScharhagSeptember 15th, 2020Last Updated: September 11th, 2020
0 116 Less than a minute

This site uses Akismet to reduce spam. Learn how your comment data is processed.