How does the embedded server work in Spring Boot (Tomcat, Jetty, Undertow)? स्प्रिंग बूट में एम्बेडेड सर्वर (Tomcat, Jetty, Undertow) कैसे काम करता है?
Spring Boot embeds a servlet container directly inside the executable JAR instead of requiring deployment to an external application server.
spring-boot-starter-web pulls in Tomcat by default; the container is auto-configured and started when SpringApplication.run() executes, bound to the port defined by server.port. Because the server is part of the JAR, the app runs with a single java -jar command, simplifying containerization. Switching to Jetty or Undertow only requires excluding the Tomcat starter and adding the alternative starter.
<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>स्प्रिंग बूट एक सर्वलेट कंटेनर को सीधे एक्ज़ीक्यूटेबल JAR के अंदर एम्बेड करता है, जिससे बाहरी एप्लिकेशन सर्वर पर डिप्लॉय करने की ज़रूरत नहीं पड़ती।
spring-boot-starter-web डिफ़ॉल्ट रूप से Tomcat लाता है; यह कंटेनर SpringApplication.run() चलने पर ऑटो-कॉन्फिगर और शुरू होता है, और server.port से जुड़ा होता है। सर्वर JAR का हिस्सा होने के कारण, ऐप एक ही java -jar कमांड से चलता है। Jetty या Undertow पर स्विच करने के लिए सिर्फ Tomcat स्टार्टर को हटाकर वैकल्पिक स्टार्टर जोड़ना होता है।
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>Was this answer clear?