Spring Boot - using environment variables in application.yml

I am trying to parameterize my file application.ymlso that I can put it in the github repository with my project, but did not find the details of connecting to the database. I want to use system environment variables for this. I am using OS X El Capitan.

I put the following lines in mine .bash_profile:

export JDBC_TODO_USER=<my-username>
export JDBC_TODO_PASS=<my-password>

and the following lines in mine application.yml:

spring:
   datasource:
   username: ${JDBC_TODO_USER}
   password: ${JDBC_TODO_PASS}

I also tried

spring:
   datasource:
   username: ${JDBC.TODO.USER}
   password: ${JDBC.TODO.PASS}

Both of them give me an error while starting the application: java.sql.SQLInvalidAuthorizationSpecException: Could not connect: Access denied for user '${JDBC_TODO_USER'@'<my-ip-address>' (using password: YES)

Of course, when I replace ${JDBC_TODO_USER}my username ${JDBC_TODO_PASS}with my password, then everything works fine. It seems that Spring does not understand that I am related to environment variables. Do I need to do some additional configuration to make it work?

+4
2

, . , , ?

echo $JDBC_TODO_USER
echo $JDBC_TODO_PASS

export

:

  • sudo vi/etc/launchd.conf
  • :
setenv JDBC_TODO_USER 
setenv JDBC_TODO_PASS
  1. .
  2. , ,

:

java -Djdbc.todo.user = myuser -Djdbc.todo.pass = mypass -jar MyProject.jar

application.yml:

spring:
   datasource:
   username: ${jdbc.todo.user}
   password: ${jdbc.todo.pass}

: http://docs.ansible.com/ansible/playbooks_vault.html https://vaultproject.io/

+3

- Eclipse, Eclipse , .bash_profile. Run → Run Configuratons... → Environment .

0

Source: https://habr.com/ru/post/1611603/


All Articles