In this tutorial, you will learn to use @ConfigurationProperties to map properties files to POJO classes in Spring Boot application. Let's get started to build a simple example with Java and Maven

What you'll need

  • JDK 8+ or OpenJDK 8+
  • Maven 3+

Stack

  • Java
  • Spring Boot

Init project structure and dependencies

Project structure

├── src
│   └── main
│       ├── java
│       │   └── com
│       │       └── hellokoding
│       │           └── util
│       │               ├── Application.java
│       │               ├── NestedProperties.java
│       │               └── SimpleProperties.java
│       └── resources
│           └── application.properties
└── pom.xml

Project dependencies


Define Properties file and handler

Properties file


Mapping Properties file into POJO classes



Config and Run

Application Bootstrap


Run with Maven

Type the below command at the project root directory

mvn clean spring-boot:run

Source code

https://github.com/hellokoding/hellokoding-courses/tree/master/springboot-examples/springboot-nested-properties-file