Enterprise Java

Quick tip: Referencing other Properties in Spring

In Spring property (or yaml) files we can reference other properties using the ${..} syntax.

For example:

1
2
3
external.host=https://api.external.com
external.productService=${external.host}/product-service
external.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}")
private String productServiceUrl; // https://api.external.com/product-service

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.

Michael Scharhag

Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
Back to top button