Using env variable in Spring Boot's

You can use environment variables in your file by using the property.

For example, you can set the property to prod in your environment, and then create a separate file that contains the properties you want to override when the prod profile is active.

In the file, you can use the ${VAR_NAME} syntax to reference an environment variable. For example:


This will use the value of the PORT environment variable as the value for the server.port property.

You can also use the property to specify the name of the .properties file that should be loaded, and the spring.config.location property to specify the location of the file. For example:

This will cause Spring Boot to load the file from the /etc/myapp/ directory.

Note that the file is always loaded, regardless of the values of the and spring.config.location properties.