An embedded server lets your Spring Boot app run as a simple program without needing a separate web server setup.
Embedded server concept in Spring Boot
spring-boot-starter-web dependency includes an embedded server like Tomcat by default. @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } }
The embedded server is included automatically with the web starter dependency.
You don't need to install or configure a separate server like Tomcat or Jetty.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}@SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } }
application.properties.server.port=8081This Spring Boot app runs with an embedded Tomcat server. When you run it, it starts the server automatically. Visiting http://localhost:8080/ shows the message.
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } @RestController class HelloController { @GetMapping("/") public String hello() { return "Hello from embedded server!"; } }
You can switch embedded servers (Tomcat, Jetty, Undertow) by changing dependencies.
Embedded servers make deployment easier but may use more memory than lightweight servers.
Use application.properties to customize server settings like port or context path.
Embedded servers let Spring Boot apps run standalone without external server setup.
They simplify development and deployment by bundling the server inside the app.
You control the embedded server via dependencies and configuration files.
Practice
Solution
Step 1: Understand embedded server purpose
Embedded servers are included inside the app, so no external server setup is needed.Step 2: Compare options
Only It allows the application to run standalone without needing an external server. correctly states the standalone running advantage. Others describe incorrect or unrelated facts.Final Answer:
It allows the application to run standalone without needing an external server. -> Option BQuick Check:
Embedded server = standalone app [OK]
- Thinking external server is still required
- Confusing embedded server with disabling HTTP
- Assuming XML config is mandatory
Solution
Step 1: Identify embedded server dependency
The embedded Tomcat server comes with the spring-boot-starter-web dependency.Step 2: Eliminate unrelated dependencies
Other options relate to data, security, or testing, not embedded servers.Final Answer:
spring-boot-starter-web -> Option DQuick Check:
Web starter includes embedded Tomcat [OK]
- Choosing data or security starters for embedded server
- Confusing test starter with server dependency
server.port=8085What will happen when you run the app with embedded Tomcat?
Solution
Step 1: Understand server.port property
Setting server.port changes the embedded server's listening port.Step 2: Apply property effect
Since 8085 is valid, the embedded Tomcat will start on port 8085.Final Answer:
The embedded server will start on port 8085. -> Option AQuick Check:
server.port sets embedded server port [OK]
- Assuming default port always used
- Thinking invalid port causes failure (8085 is valid)
- Confusing port 80 as default
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}If you remove the embedded server dependency, what will happen when you run this app?
Solution
Step 1: Understand dependency role
spring-boot-starter-web provides the embedded server. Without it, Spring Boot runs as a non-web application.Step 2: Effect of removing embedded server dependency
The app starts successfully, but no web server runs since no web dependencies are present.Final Answer:
The app will start but no web server will run. -> Option CQuick Check:
No web starter = app starts, no server [OK]
- Thinking app fails to start without server dependency
- Believing external server auto-starts
- Assuming Jetty starts by default without dependency
Solution
Step 1: Understand default embedded server
Spring Boot uses Tomcat by default with spring-boot-starter-web.Step 2: How to switch embedded server
You must exclude Tomcat dependency and add Jetty starter to replace it.Final Answer:
Exclude spring-boot-starter-tomcat and add spring-boot-starter-jetty dependency. -> Option AQuick Check:
Exclude Tomcat + add Jetty = switch server [OK]
- Adding Jetty without excluding Tomcat causes conflicts
- Changing port does not switch server
- Adding Undertow starter switches to Undertow, not Jetty
Ready to prove it?
Pass the test and this pattern moves unknown
