Spring Boot nhúng web server (Tomcat, Jetty, Undertow) vào JAR — deploy như file thực thi, không cần cài server riêng.
Mặc định: Tomcat (khi dùng spring-boot-starter-web).
Thay sang Jetty:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>So sánh:
| Tomcat | Jetty | Undertow | |
|---|---|---|---|
| Default | ✅ | ❌ | ❌ |
| Memory | Trung bình | Thấp | Thấp |
| HTTP/2 | ✅ | ✅ | ✅ |
| WebSocket | ✅ | ✅ | ✅ |
| Use case | General | Lightweight/embeddable | High concurrency |
# application.yml
server:
port: 8080
servlet.context-path: /app
tomcat:
max-threads: 200
connection-timeout: 20000Ưu điểm Embedded Server:
- Deploy: java -jar app.jar — một lệnh, không setup.
- Microservices: mỗi service có server riêng, cấu hình độc lập.
- Docker-friendly: build image đơn giản.
Spring Boot embeds a web server (Tomcat, Jetty, Undertow) into the JAR — deploy as an executable, no separate server installation needed.
Default: Tomcat (with spring-boot-starter-web).
Switch to Jetty:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>Comparison:
| Tomcat | Jetty | Undertow | |
|---|---|---|---|
| Default | ✅ | ❌ | ❌ |
| Memory | Medium | Low | Low |
| HTTP/2 | ✅ | ✅ | ✅ |
| WebSocket | ✅ | ✅ | ✅ |
| Use case | General | Lightweight/embeddable | High concurrency |
# application.yml
server:
port: 8080
servlet.context-path: /app
tomcat:
max-threads: 200
connection-timeout: 20000Embedded server benefits:
- Deploy: java -jar app.jar — one command, no setup.
- Microservices: each service has its own server with independent config.
- Docker-friendly: straightforward image builds.