1

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.

montt
  • 11
  • 1
  • You are right that you cannot use SpEL in properties files. Does https://stackoverflow.com/questions/29072628/how-to-override-spring-boot-application-properties-programmatically answer your question? You should be able to use a `EnvironmentPostProcessor` to set the properties programmatically. You could use SpEL within that, via `@Value` – Michael Jan 06 '20 at 12:53
  • Did You thougth of getting the os-dependent information out of the application.yml? Maybe the _right_ information is already there on the target system? – Tobias Otto Jan 06 '20 at 13:03

0 Answers0