0

I want to enable flyway only if environment is dev for other environments it should be disabled. It can be define while creating a profile for each environment but there is only one profile.

I tried couple version of below script but I had string cast problem.

flyway:
    enabled: ${env} == 'dev'
mgnfcnt
  • 77
  • 11
  • Does this answer your question? https://stackoverflow.com/questions/34845990/spring-use-one-application-properties-for-production-and-another-for-debug – Benjamin M Aug 17 '21 at 14:40
  • Create an environment specific config which sets this to `true` and set the default to `false`. – M. Deinum Aug 17 '21 at 14:42
  • @M.Deinum It is also an option but we need to change whole stack due to it is aws env. and requires ops team to it. I just wonder to perform without it – mgnfcnt Aug 17 '21 at 14:44
  • Why would you need the ops team? Just include a file into your application and you are done. – M. Deinum Aug 17 '21 at 14:47
  • @M.Deinum permission lacks :) enterprise world – mgnfcnt Aug 17 '21 at 14:48
  • If you can create this what you have now you can create a file. That has nothing to do with permissions. – M. Deinum Aug 17 '21 at 14:50
  • @aksappy `'#{"${env:}".equals("dev") ? true : false"}' ` give error as string to boolean problem, but this is what I actually want to do. Reason: failed to convert java.lang.String to boolean – mgnfcnt Aug 18 '21 at 11:52

1 Answers1

0

Building on the answer in post, the following SpEL in application.yaml does the trick.

Spring will automatically convert string representations of true and false to a Boolean while resolving properties.

flyway.enabled: '#{ "${env:false}".equals("dev") ? "true" : "false" }'
aksappy
  • 3,400
  • 3
  • 23
  • 49
  • Failed to bind properties under 'spring.flyway.enabled' to boolean: ``` Property: spring.flyway.enabled Value: '#{ "${env:false}".equals("dev") ? "true" : "false" }' Origin: class path resource [application.yml]:57:14 Reason: failed to convert java.lang.String to boolean ``` – mgnfcnt Aug 18 '21 at 13:58
  • I have created a working example in [github](https://github.com/aksappy/spring-spel-demo). Let me know what is the difference from your project. – aksappy Aug 18 '21 at 16:21
  • The difference is you havent used flyway library and there is no dependency that require this property as boolean – mgnfcnt Aug 19 '21 at 06:34