0
0
Spring Bootframework~30 mins

Why configuration matters in Spring Boot - See It in Action

Choose your learning style9 modes available
Why configuration matters
📋 What You'll Learn
💡 Why This Matters
🌍 Real World
In real applications, configuration lets you change messages, URLs, or feature flags without changing code. This makes apps easier to maintain and deploy.
💼 Career
Understanding configuration in Spring Boot is essential for backend developers to build flexible and maintainable applications.
Progress0 / 4 steps
1
Create the greeting property in application.properties
Create a file named src/main/resources/application.properties and add a property called app.greeting with the value Hello, Spring Boot!.
Spring Boot
Need a hint?

This file holds configuration values. Adding app.greeting=Hello, Spring Boot! sets the greeting message.

2
Create a configuration class to read the greeting
Create a Java class named GreetingConfig in package com.example.demo. Use @ConfigurationProperties(prefix = "app") to bind the app.greeting property to a String greeting field with getter and setter.
Spring Boot
Need a hint?

Use @Component and @ConfigurationProperties(prefix = "app") to bind properties. Add a private field greeting with getter and setter.

3
Create a REST controller to return the greeting
Create a class named GreetingController in package com.example.demo. Add @RestController. Inject GreetingConfig via constructor. Create a GET endpoint /greet that returns the greeting from GreetingConfig.
Spring Boot
Need a hint?

Use @RestController and constructor injection. Create a method with @GetMapping("/greet") that returns the greeting.

4
Enable configuration properties scanning
In your main application class DemoApplication in package com.example.demo, add @EnableConfigurationProperties(GreetingConfig.class) above the class declaration to enable binding of configuration properties.
Spring Boot
Need a hint?

Add @EnableConfigurationProperties(GreetingConfig.class) above your main application class to enable configuration binding.