We have executable spring boot jars. Some environment variables are provided via the runtime account's .bashrc , including SPRING_PROFILES_ACTIVE . This is set at runtime through checking some system parameters.
In order to enable a truly portable application, we would like to set these variables inside a custom version of the Spring Boot executable launch script (launch.script) instead of relying upon a custom .bashrc being deployed somewhere.
i.e. the launch script runs the custom shell code that is currently in our bashrc .
We could then throw the Spring Boot executable jar on one of our boxes without having to deploy the custom .bashrc .
We have copied the default Spring Boot launch.script and prepended setting our environment variables. We replace the default script with our custom one by using the spring-boot-maven-plugin. Using echo statements, we know that the new launch.script replaces the default one.
One environment variable we are setting dynamically is SPRING_PROFILES_ACTIVE . Through an echo statement, I know that the variable is being set correctly inside of our custom launch.script. However, that value is not being propagated to the application. i.e. the spring profile at application startup is always 'default', versus L0, L1 or whatever we're trying to set.
I have exported the variable using export and declare -x .
Is what we are doing at all feasible, or is setting SPRING_PROFILES_ACTIVE in the launch.script too late ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…