Creating custom properties
We have already dabbled with application properties in a couple of places in this book. Remember setting spring.mustache.servlet.expose-request-attributes=true
in the application.properties
file in Chapter 4, Securing an Application with Spring Boot?
Configuring our application using property files is incredibly handy. While Spring Boot offers many custom properties we can use, it’s possible to create our own!
Let’s start by creating some custom properties. To do that, create a brand new AppConfig
class, like this:
@ConfigurationProperties("app.config") public record AppConfig(String header, String intro, List<UserAccount> users) { }
This Java 17 record can be described as follows:
@ConfigurationProperties
: A Spring Boot annotation that flags this record as a source of property settings. Theapp.config
value is the prefix for its properties.AppConfig
: The name of this bundle of type-safe...