I'm trying to parametrize my application.yml
file so I can put it on github repo with my project, but not reveal database connection details. I want to use system environment variables to do so. I use OS X El Capitan.
I put following lines in my .bash_profile
:
export JDBC_TODO_USER=<my-username>
export JDBC_TODO_PASS=<my-password>
and following lines in my 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 those give me an error during start of the app:
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}
with my username and ${JDBC_TODO_PASS}
with my password then everything works fine. It looks like Spring does not understand that I refer to environment variables. Do I need to do some additional configuration to make it work?
It is quite likely that your environment variables are not being made available. Have you tried the following to see if they are accessible?
echo $JDBC_TODO_USER
echo $JDBC_TODO_PASS
or
export
A sure-fire way to ensure they are available is to:
setenv JDBC_TODO_USER setenv JDBC_TODO_PASS
You can also try system properties:
java -Djdbc.todo.user=myuser -Djdbc.todo.pass=mypass -jar MyProject.jar
with the following in your application.yml:
spring:
datasource:
username: ${jdbc.todo.user}
password: ${jdbc.todo.pass}
But ultimately for storing user credentials in a production environment I would recommend one of the following: http://docs.ansible.com/ansible/playbooks_vault.html https://vaultproject.io/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With