1

How do you pass a parameter as an environment variable?

Step 1: Open up user bash file 'vim ~/.bash_profile', write the environment variable and save the file

export TWLIO_NUMBER=+303....

Step 2: In the application porperties file, store the variable

twlio_number=${TWLIO_NUMBER}

Step 3: Import Value in order to use it

  import org.springframework.beans.factory.annotation.Value;

  @Value("${twlio_number}")
  private String TWILIO_NUMBER;

Also, if I hardcode the value in the application properties file, the code works.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Mike
  • 83
  • 8

2 Answers2

1

Pass those as Java-Opts. It will work.

How to pass JVM arguments in SpringBOOT

https://www.baeldung.com/spring-boot-command-line-arguments

0

So I have a system variable in my spring project.

String dataSourceUrl = System.getenv(DEFAULT_CONNECTION);

I am looking for something quick to set the variable in command line.

  1. I found this command work in mac export DEFAULT_CONNECTION=value (value wrap in single quote to prevent the values being replaced)
  2. You can check by env | grep DEFAULT_CONNECTION
  3. run as usual mvn spring-boot:run
BabyishTank
  • 1,329
  • 3
  • 18
  • 39