0

I would like to replace a configuration yml property using a condition based on environnement variables :

spring:
  datasource:
    username:${ENV} == 'PROD' ? ${USER_PROD} : ${USER_TEST}
    password: ${ENV} == 'PROD' ? ${PWD_PROD} : ${PWD_PROD}

Is there any way I can do this inside my application.yml or programmaticaly ?

I have not faced this situation before

  • Don't. Instead provide profile specific property files or pass the password/user at runtime. Else you endup with programming in properties or yaml files. – M. Deinum Nov 15 '22 at 09:42

2 Answers2

1

The normal way of doing this is to use different application.properties file each representing a "profile".

Then you can override the desired properties based on the profile and run the application using that profile using -Dspring.profiles.active.

A useful guide on the following link.

atish.s
  • 1,534
  • 11
  • 19
0

you can use separate config files and properties for different Spring Profiles.

please read this guide for more info: Guide

Tom Elias
  • 751
  • 6
  • 15