Common Settings

Settings You Will Use Often

PropertyDefaultMeaning
server.port8080HTTP port (use 0 for a random free port)
server.servlet.context-path/prefix for every URL, e.g. /shopease
spring.application.name-app name, shown in logs and used by Spring Cloud
spring.profiles.active-which profiles are active
logging.level.*INFOlog levels per package
spring.jackson.default-property-inclusionalwayse.g. non_null to hide null fields in JSON
spring.main.banner-modeconsoleoff hides the Spring banner

Overriding Without Editing the File

Every property can be overridden at run time. Later sources win over earlier ones (simplified order):

application.properties / .yml  <  environment variables  <  command-line arguments
        (lowest)                       SERVER_PORT=9090            --server.port=9091
                                                                   (highest)

Example

Environment variable names are the property in upper case with dots and dashes replaced by underscores:

SERVER_PORT=9090 java -jar target/shopease-0.0.1-SNAPSHOT.jar
java -jar target/shopease-0.0.1-SNAPSHOT.jar --server.port=9091

Example output

... Tomcat started on port 9090 (http) with context path '/'
... Tomcat started on port 9091 (http) with context path '/'

Tip: On Windows PowerShell set the variable first: $env:SERVER_PORT=9090; java -jar ...

Practice

Exercise: Make ShopEase run on port 8085 with every URL starting with /shopease, and hide null fields in JSON. Write it in YAML.

Show answer
server:
  port: 8085
  servlet:
    context-path: /shopease
spring:
  jackson:
    default-property-inclusion: non_null
# Now: http://localhost:8085/shopease/ping