5

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

  1. start Tomcat using the above script,
  2. deploy the Spring Boot application from IntelliJ Idea, and
  3. 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)?

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • In Intellij: Run -> Run.... -> Edit Configurations... : there's a field for Environment variables. You can add key-value pairs there (key: MAIL_HOSTNAME value: smtp.provider.com). If you're not running from Intellij, adding `export MAIL_HOSTNAME="smtp.provider.com"` to the script might work. – Albert Hendriks Jul 08 '20 at 11:02
  • @AlbertHendriks I'm using "Tomcat, remote" ( https://imgur.com/FqZIt01 ) configuration and cannot find environment variable panel there. – Glory to Russia Jul 08 '20 at 13:48

2 Answers2

4
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.

Konstantin Kolinko
  • 3,854
  • 1
  • 13
  • 21
0

It is not possible to pass JVM arguments to a process running in a remote machine from an IDE. The Spring Boot params will be loaded from the JVM params when the process is started in the remote machine. I am sorry to say that it won't work.

An alternate solution i suggest is, use spring config server to create a separate profile for remote debugging config ( like we will have for Dev, QA environments etc ). When you try to debug the application, please restart the remote application using jenkins job ( I am assuming you don't have remote acccess to the box where the app is running) by passing the profile name in the jenkins job so that the values you wanted will be picked up. Please let me know if you need more details.