0
0
Spring Bootframework~30 mins

Application.properties basics in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Application.properties basics
📖 Scenario: You are creating a simple Spring Boot application that needs configuration settings for the server port and application name.
🎯 Goal: Learn how to set up and use the application.properties file to configure basic Spring Boot application properties.
📋 What You'll Learn
Create an application.properties file with specific properties
Add a property for server.port with value 8085
Add a property for spring.application.name with value MyApp
Access these properties in a Spring Boot component using @Value annotation
Print the configured values inside a CommandLineRunner bean
💡 Why This Matters
🌍 Real World
Setting application properties is essential for configuring Spring Boot apps without changing code. It helps manage environments and customize behavior.
💼 Career
Understanding application.properties and property injection is a fundamental skill for Spring Boot developers working on real-world backend services.
Progress0 / 4 steps
1
Create application.properties file with server port
Create an application.properties file and add the line server.port=8085 to set the server port.
Spring Boot
Need a hint?

The application.properties file is where Spring Boot reads configuration values. Setting server.port changes the port your app runs on.

2
Add application name property
In the same application.properties file, add the line spring.application.name=MyApp to set the application name.
Spring Boot
Need a hint?

The spring.application.name property helps identify your app in logs and monitoring.

3
Create a Spring Boot component to read properties
Create a Java class named AppConfigReader annotated with @Component. Use @Value to inject server.port into an int serverPort field and spring.application.name into a String appName field.
Spring Boot
Need a hint?

Use @Value("${property.name}") to inject property values into fields.

4
Print properties using CommandLineRunner
In your main Spring Boot application class, create a CommandLineRunner bean that injects AppConfigReader and prints the serverPort and appName values.
Spring Boot
Need a hint?

Use a CommandLineRunner bean to run code after the app starts. Inject your AppConfigReader to access properties.