I heard that Spring Boot application includes an embedded HTTP server. However, after I run gradlew I got a war file, which I just drop into Tomecat's webapp directory. Obviously the WAR file does not include an embedded HTTP server. So is my build.gradle file somehow configured to exclude HTTP server? If so which option is for this purpose?
-
Please ask one question at a time - it seems like you already asked the part I edited out at https://stackoverflow.com/q/62934516/3001761. – jonrsharpe Jul 20 '20 at 15:23
2 Answers
That depends on how you manage your spring boot project. With maven or gradle, usually when creating WAR spring boot project's you mark servlet container dependency as provided (it will be provided by servlet where WAR will be deployed).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
That means all the functionality implementation's comming from this dependency will not be packed within final artifact but will be provided by environment where this artifact will be deployed. (Tomcat server for example.)
On the other hand if you don't mark your servlet dependency as provided it will be packed with project (as embedded server, but there is more magic behind this) which create's stand alone application. Note that packaging of the project with embedded server should be changed to JAR as well. Also this does not apply to Reactor project's which don't use servlet's.

- 741
- 5
- 18
-
Please also follow this link as there are few other differences i didn't mention. https://www.baeldung.com/spring-boot-war-tomcat-deploy – Norbert Dopjera Jul 20 '20 at 15:43
The default spring boot application, with only spring-boot-starter
as dependency does not contain an embedded servlet by default.
However, if you have a spring-boot-starter-web
application, there IS an embedded tomcat servlet.
Here you can see the Gradle dependencies that are imported whenever you use spring-boot-starter-web
. You can see it includes the following line of code:
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat"))
That brings us to the spring-boot-starter-tomcat
-dependency that is automatically imported. [Here][2]
, we see the following:
api("org.apache.tomcat.embed:tomcat-embed-core") {
exclude group: "org.apache.tomcat", module: "tomcat-annotations-api"
}
Thus, you can see how and where Spring Boot includes the embedded servlet dependency.

- 48
- 3