I'm using Mac OS Mojave with Spring STS version 3.9.7.
So I'm trying to load some environment variables such as database username & password into my application.properties file but Spring fails to load them into.
I'v used this command to set the username environment variable:
export ABC_DB_UNAME=some_username
and when I do echo $ABC_DB_UNAME or printenv I can see the value.
In my application.properties file I set the username as below:
spring.datasource.username=${ABC_DB_UNAME}
Now when running my spring sts from the IDE itself, it is not able to pick up the values and it throws an exception that
access is denied for ABC_DB_UNAME@database_endpoint.
It clearly shows that spring sts is not picking up my environment variables.
What makes it more twisting for me is that when I run the spring app via maven using the below command, it picks up the environment variables and it works just fine.
mvn spring-boot:run
but using the mvn command I don't know how I can make the IDE to trigger the breakpoints for me to debug as well.
EDIT : Testing and trying to print the environment variable using the code System.getenv("ABC_DB_UNAME") and System.getProperty("ABC_DB_UNAME") also returns null but maven still works.
I think the environmental variable is set temporarily in the terminal. Hence the mvn spring-boot:run
works. You can run it in different terminal, it should fail
You need to set the ${ABC_DB_UNAME} in the bashrc (mac) to persist it permanently. or you can pass the environmental variable as argument during running the app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.