Issue
I have a Spring Boot application, which runs in an Apache Tomcat server. In application.yaml
I have, among others, following entries:
mail:
pop3Host: ${MAIL_HOSTNAME}
inboxFolder: ${MAIL_INBOX}
hostName: ${MAIL_HOSTNAME}
port: ${MAIL_PORT}
userName: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}
The application is deployed to Tomcat from within IntelliJ Idea so I can debug it.
I start Tomcat using the following command:
export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8090,server=y,suspend=n"
export JAVA_OPTS=" -DMAIL_HOSTNAME='smtp.provider.com' -DMAIL_INBOX='MAIL_INBOX' -DMAIL_PORT='587' -DMAIL_USERNAME='username' -DMAIL_PASSWORD='XXXXXXXX'"
export CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8090,server=y,suspend=n"
./catalina.sh jpda start
However, after I
- start Tomcat using the above script,
- deploy the Spring Boot application from IntelliJ Idea, and
- make sure that the code where those values are used is executed,
I get the exception indicating that the placeholders have not been substituted.
How can I fix it, i. e. make sure that I can specify some information (like user name and password) in application.yaml
via environment variables (so that I don't include the actual credentials in application.yaml
)?
Solution
export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8090,server=y,suspend=n"
export JAVA_OPTS=" -DMAIL_HOSTNAME='smtp.provider.com' -DMAIL_INBOX='MAIL_INBOX' -DMAIL_PORT='587' -DMAIL_USERNAME='username' -DMAIL_PASSWORD='XXXXXXXX'"
export CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8090,server=y,suspend=n"
./catalina.sh jpda start
Add export MAIL_HOSTNAME=
etc. to the above lines, or create a setenv.sh
file with such lines (in the same directory as catalina.sh
file).
Using setenv.sh
is documented in RUNNING.txt
file of Apache Tomcat.
Answered By - Konstantin Kolinko
Answer Checked By - Senaida (JavaFixing Volunteer)