Home > Mobile >  affect env variables to Spring boot application properties
affect env variables to Spring boot application properties

Time:11-26

I am looking for a way to map my Linux server environment variables to my keys in the application properties file.

spring.mail.username={value} spring.mail.password={value} spring.mail.properties.mail.smtp.port={value}

{value} would come from system defined environment variables.

CodePudding user response:

OS environment variables are also taken into account by Spring Boot. You just need to name them accordingly (SPRING_MAIL_USERNAME for example). You can check more info on how Spring Boots reads external configuration at the reference documentation.

CodePudding user response:

You could get from two ways

Replacing properties var with environment var

If You set an enviromment var will override var on properties

Set on env

# we can override all properties var replacing  "." to "_"
SERVER_PORT=8009 

and set on .properties

# this will be overrided by SERVER_PORT var
server.port=8001 

Using vars on .properties

You can use environment vars on .properties with ${name_env_var}

server.port=${SERVER_PORT_ENV:default_value_if_env_not_found}

  • Related