A few quick steps of configuring properties in spring boot, How can it help a developer?

Spring Boot is a way by which you can bootstrap or quickly create any Spring application. Spring Framework is for developing various web and enterprise applications. It has developed various projects over time and Spring Boot is one of them.

  • It helps you to create Spring applications faster.
  • You don’t have to deploy JAR as it comes with an embedded tomcat or jetty server.
  • Spring Boot is an application configuration with an external properties file.
  • It reduces development code by avoiding a lot of boilerplate code.
  • It helps you create Spring applications quickly.
  • No worry about version mismatches.
  • It allows you to create sample projects using spring boot initializer.
  • Spring Boot also takes the responsibility of managing versions of dependent libraries. Just migrate to the latest version of Spring Boot, and the corresponding compatible versions of all the frameworks being used are directly available for you.

A Quick Setup

add spring-boot-starter-parent as the parent in our pom.xml

    	<groupId> org.springframework.boot	</groupId>
    	<artifactId> spring-boot-starter-parent	</artifactId>
    	<version> 2.1.3.RELEASE	</version>
    	<relativePath/>; 	<!-- lookup parent from repository -->;


We configure properties using POJOs

@ConfigurationProperties(prefix = &quot;mail&quot;)
public class ConfigProperties {

    private String hostName;
    private int port;
    private String from;

    // getters and setters

@Configuration is used so that Spring creates a Spring bean in the application context.
@ConfigurationProperties works best with properties that all have the same prefix

If we don’t use @Configuration in the POJO, then we need to add @EnableConfigurationProperties(ConfigProperties.class) in the main Spring application class to bind the properties into the POJO:

public class SpringDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringDemoApplication.class, args);

Spring will automatically bind any property defined in our property file that has the prefix mail and the same name as in the fields in the ConfigProperties class


Nested Properties

We can have nested properties in Lists, Maps, and Classes

public class Credentials {
    private String authMethod;
    private String username;
    private String password;

    // getters and setters
public class ConfigProperties {

    private String host;
    private int port;
    private String from;
    private List defaultRecipients;
    private Map&amp;lt;String, String&amp;gt; additionalHeaders;
    private Credentials credentials;
    // getters and setters
#Simple properties

#List properties

#Map Properties

#Object properties

Property Validation

private String hostName;
private String hostName;
@Length(max = 4, min = 1)
private String authMethod;
private int port;
@Pattern(regexp = &quot;^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$&quot;)
private String from;

Immutable @ConfigurationProperties binding

@ConfigurationProperties(prefix = &quot;mail.credentials&quot;)
public class ImmutableCredentials {

    private final String authMethod;
    private final String username;
    private final String password;

    public ImmutableCredentials(String authMethod, String username, String password) {
        this.authMethod = authMethod;
        this.username = username;
        this.password = password;

    public String getAuthMethod() {
        return authMethod;

    public String getUsername() {
        return username;

    public String getPassword() {
        return password;


How can Spring Boot help a developer?

  • Integration with several frameworks
  • Configuration management
  • Logging
  • Transaction management
  • Error/Exception handling
  • Monitoring and health checks
  • Integrating unit testing and mocking frameworks


We have explored the @ConfigurationProperties annotation and some of the features it provides like data binding and Bean Validation. Spring Boot makes the life of a developer a lot easier by providing important debug and deployment tools. Spring Boot adds some intelligence with autoconfiguration. All we need to do is provide the frameworks that are needed by the application, and Spring Boot magically auto-configures them!

It reduces project startup time to a large extent and provides an easy mechanism termed as starter projects for the development of different applications.

How may I help you?
    Type your message...