1

In Spring I can reference some other property value as variable in a property source

base:
  hostName: foo.baa.com

services
  serviceUrl: http://${base.hostName}/fooService

This returns http://foo.baa.com/fooService. But only if base.hostName ist defined in the same file. If it's defined in another PropertySource I get http://${base.hostName}/fooService.

Can I get this running over several PropertySources?

EDIT: It was just a stupid typo. You can perfectly fine reference variables defined in other PropertySources

mibutec
  • 2,929
  • 6
  • 27
  • 39
  • Where is the *other* property file located? is it used by another application or you intend to read the file directly? – Aman Oct 29 '20 at 20:09
  • I have to withdraw my question, just had a stupid bug in my code. You can perfectly fine include variables defined in other PropertySources – mibutec Oct 30 '20 at 04:53
  • can you mention how you did it, since it was not clear how you intended to include it? – Aman Oct 30 '20 at 07:24
  • I have one property file hoding all the `base.*` properties and one holding the `service.*` properties. Both are loaded by different PropertySourcs, but both in the same `ApplicationContext`. And as said: When doing it right, it works. – mibutec Nov 05 '20 at 08:43

1 Answers1

0

There is no simple way of importing another yml into another in Spring... However, you can make a workaround with the usage of spring.profiles.include property. More explanation here: Spring "spring.profiles.include" overrides

Marcin Rzepecki
  • 578
  • 4
  • 10