I need to configure a Spring property (in my case, for Flyway) in application.yml depending on the type of OS the application is run on. AFAIK, Spring does not support SpEL expressions in YAML files.
So far, the best solution I could come up with uses the Java system property os.name
and a lookup property:
spring:
flyway:
collations:
Linux: de_DE
Windows 10: de-DE-x-icu
Windows 8.1: de-DE-x-icu
Windows 7: de-DE-x-icu
placeholders:
collation: ${spring.flyway.collations.${os.name}:de_DE}
This is very ugly, mainly because all possible values for os.name
need to be explicitly enumerated as full literals.
Is there a better way to do this? Maybe delegate spring.flyway.placeholders.collation
to some Configuration Bean to be set programmatically? This also needs to work for unit tests BTW.