Link Search Menu Expand Document

In each Spring Boot application, there are values that can be configured without having to recompile the Java code.

These are typically configured in a file called which lives under:


In practice, it may feel like you have to recompile, because you still have to run mvn:package or spring-boot:run which packages up this file into it’s proper location in the jar file or target directory. However, no actual Java source get recompiled to make the changes that you make in take effect.

Examples of things that go in

The most common thing you’ll see in are these two lines:

server.port: ${PORT:8081} DEBUG

What about application.yml

Note that some applications will use src/main/resources/application.yml which serves the same function, but uses a different syntax.

Should go into git?

Typically we do put into git, but we need to be careful.

  • Some things that go into are meant to be kept secret such as database passwords
  • Other things are things that are meant to be configured as you run or debug (e.g. debug levels), or adjusted for development, QA and production

We’ll discuss more how to handle these cases as they arise. The most important one is handling secrets, which is discussed below.

Handling Secrets

Note that some instructions will tell you to put certain things in the that should really NEVER go into git.

One way of handling this is to define an Environment Variable.

  • When running on localhost, this is a Unix, MacOS, or Windows Environment Variable.
  • When running on Heroku, this is a Config Variable.

Names of environment variables are, by convention, all upper case and use snake case (underscores).

The environment variable used by Spring Boot to override values is called SPRING_APPLICATION_JSON. It shoudl be set equal to a JSON string that defines keys/values for each application property that needs to be override or supplement the values in the file.

An example of this is illustrated in the repo:

More on