0
0
Spring Bootframework~30 mins

Embedded server concept in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Embedded Server Concept in Spring Boot
📖 Scenario: You are building a simple Spring Boot web application that runs with an embedded server. This means the server is included inside your application, so you don't need to install or configure a separate web server.This setup is common for microservices and makes deployment easier.
🎯 Goal: Create a basic Spring Boot application with an embedded Tomcat server that starts automatically and serves a simple web page.
📋 What You'll Learn
Create a Spring Boot application class with the @SpringBootApplication annotation
Add a configuration property to set the server port to 8081
Create a REST controller with a GET endpoint /hello that returns a welcome message
Ensure the application runs with the embedded server on port 8081
💡 Why This Matters
🌍 Real World
Embedded servers allow developers to package web applications with their own server, simplifying deployment and making applications portable.
💼 Career
Understanding embedded servers is essential for modern Java backend development, especially in microservices and cloud-native applications.
Progress0 / 4 steps
1
Create the Spring Boot application class
Create a class called EmbeddedServerApplication in package com.example.demo. Annotate it with @SpringBootApplication and add the main method that runs SpringApplication.run(EmbeddedServerApplication.class, args).
Spring Boot
Need a hint?

Use @SpringBootApplication on the class and add a main method that calls SpringApplication.run.

2
Configure the embedded server port
Create a file named application.properties in src/main/resources. Add the line server.port=8081 to set the embedded server port to 8081.
Spring Boot
Need a hint?

The embedded server port is set in application.properties with server.port=8081.

3
Create a REST controller with a GET endpoint
Create a class called HelloController in package com.example.demo. Annotate it with @RestController. Add a method sayHello annotated with @GetMapping("/hello") that returns the string "Welcome to the embedded server!".
Spring Boot
Need a hint?

Use @RestController on the class and @GetMapping("/hello") on the method that returns the welcome string.

4
Run the application with embedded server
Ensure the application class EmbeddedServerApplication has the main method that runs the Spring Boot application. This will start the embedded Tomcat server on port 8081 automatically.
Spring Boot
Need a hint?

The main method must call SpringApplication.run to start the embedded server.