I'm trying to pass custom heroku config variable into application.properties but no value is passed.
My application.properties entry:
spring.mail.username=${SPRING_MAIL_SENDER_USERNAME}
Then I inject this value into String variable:
@Value("${spring.mail.username}")
private String SENDER_MAIL_USERNAME;
but the SENDER_MAIL_USERNAME is an empty string when I try to use it.
I can get the proper value like this:
System.getenv("SPRING_MAIL_SENDER_USERNAME");
but this is not what I'm looking for. Anyone knows what I'm doing wrong here?
EDIT:
Maybe it's worth to add that my project uses maven with 2 modules (backend and frontend). Simplified project structure looks like this:
-app
-backend
-src.main
-java.com.jakubeeee.app
-some java files...
-resources
-application.properties
-frontend
-src
-some web files...
I also use Procfile that contains:
web: java -Dserver.port=$PORT -jar $PATH_TO_JAR
where $PATH_TO_JAR is heroku config variable with value:
backend/target/myjarname.jar
What you show here should work. Double check spelling, etc. Otherwise, you can pass the option in the Procfile as a Java property like this:
web: java -Dspring.mail.username=${SPRING_MAIL_SENDER_USERNAME} -jar target/myapp.jar
Also be sure to confirm that it works with a hardcoded value like spring.mail.username=foo (otherwise you'll know it's something other than the env).
EDIT:
I realize now that you're using a .properties file and not a .yml file. I'm unsure if env vars are supported in Spring's application.properties. You might want to try application.yml config instead.
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