Reputation: 103
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.
Upvotes: 1
Views: 2703
Reputation: 1482
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.
export DEFAULT_CONNECTION=value
(value wrap in single quote to prevent the values being replaced)mvn spring-boot:run
Upvotes: 0
Reputation: 516
Pass those as Java-Opts. It will work.
How to pass JVM arguments in SpringBOOT
https://www.baeldung.com/spring-boot-command-line-arguments
Upvotes: 1