Spring Boot nhúng web server (Tomcat default, Jetty, Undertow) trực tiếp vào JAR — không cần deploy lên app server ngoài.
java -jar app.jar # chạy, không cần Tomcat/JBoss/WildFly cài sẵnLợi ích:
- 1 artifact duy nhất (JAR chứa cả code + server).
- Environment consistency — dev/staging/prod cùng runtime.
- Container-friendly — Docker/Kubernetes chỉ cần JDK + JAR.
- Operations đơn giản — không quản lý app server riêng.
Đổi server:
<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-undertow</artifactId>
</dependency>Cấu hình: server.port=8080, server.servlet.context-path=/api.
Trade-off: mỗi service có Tomcat riêng (tốn memory hơn vs shared server truyền thống) — chấp nhận được cho microservices, cloud-native.
Spring Boot embeds the web server (Tomcat by default, Jetty, Undertow) directly into the JAR — no external app server to deploy to.
java -jar app.jar # runs, no pre-installed Tomcat/JBoss/WildFlyBenefits:
- A single artifact (JAR contains code + server).
- Environment consistency — same runtime in dev/staging/prod.
- Container-friendly — Docker/Kubernetes only need JDK + JAR.
- Simple ops — no separate app server to manage.
Switching servers:
<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-undertow</artifactId>
</dependency>Configuration: server.port=8080, server.servlet.context-path=/api.
Trade-off: each service has its own Tomcat (more memory than a shared traditional server) — acceptable for microservices and cloud-native apps.