Quick revision
The short answer
We set the packaging to war, make the application class extend SpringBootServletInitializer and override configure() to point at it, and mark spring-boot-starter-tomcat as provided so the war does not bring its own Tomcat. The external server must support the Jakarta Servlet API that Boot 3 needs, which means Tomcat 10.1 or later. And we accept that server.* settings such as server.port no longer apply, because the external container controls ports, the context path and its thread pool.
What to remember
In this answer, we deployed a Spring Boot 3 application as a war to an external Tomcat by setting the packaging to war, extending SpringBootServletInitializer and overriding configure() to point at the application class, and marking spring-boot-starter-tomcat as provided. We saw that the server must support Jakarta Servlet, Tomcat 10.1 or later for Boot 3, and that server.* settings such as server.port and the context path no longer apply because the external container controls them.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We set the packaging to war, make the application class extend SpringBootServletInitializer and override configure() to point at it, and mark spring-boot-starter-tomcat as provided so the war does not bring its own Tomcat. The external server must support the Jakarta Servlet API that Boot 3 needs, which means Tomcat 10.1 or later. And we accept that server.* settings such as server.port no longer apply, because the external container controls ports, the context path and its thread pool.
Why this question is asked
Most Spring Boot applications run as executable jars, but some organisations still operate shared Tomcat servers, and a team may need to deploy into one. Interviewers ask this to check that we know both how Boot plugs into an external servlet container and the trap of the javax to jakarta change. In this answer, we will recap how a war starts compared with a jar, make the three code and build changes, choose a compatible Tomcat, see which settings stop working, and look at keeping the war runnable on its own.
1A Quick Recap: Who Starts Whom
With an executable jar, our main method starts Spring, and Spring starts an embedded Tomcat inside the same process. With a war, it is the other way round: Tomcat is already running, it unpacks our war, and it must find a way to start Spring inside its web application context.
The way it finds us is a standard servlet feature. On start-up, a Servlet 3.0+ container looks for implementations of ServletContainerInitializer on the war's classpath. Spring provides one, SpringServletContainerInitializer, which in turn looks for classes implementing Spring's WebApplicationInitializer. SpringBootServletInitializer is such a class, and when Tomcat calls it, it builds and runs the SpringApplication, registering the DispatcherServlet with the external container instead of starting an embedded one.
6 messages in order. Play them, or step through them one at a time.
2Change 1 and 2: Packaging and the Servlet Initializer
First we change the packaging, then we give Tomcat an entry point.
configure() tells Boot which configuration classes to start, which is what the main method normally passes to SpringApplication.run(). The main method can stay; Tomcat ignores it, but developers can still run the application from the IDE. With Gradle, we apply the war plugin instead of changing the packaging, and the bootWar task builds the deployable war.
3Change 3: Tomcat as a Provided Dependency
spring-boot-starter-web pulls in spring-boot-starter-tomcat, which contains the embedded Tomcat jars. In a war for an external Tomcat, those jars would sit in WEB-INF/lib next to the server's own Tomcat classes, which at best wastes space and at worst causes class conflicts. So we mark the starter as provided: available at compile time, but not packaged into WEB-INF/lib.
Notice that Boot's repackaged war puts provided dependencies into WEB-INF/lib-provided. An external Tomcat ignores that directory, so the war deploys cleanly, but java -jar orders.war can still use those jars to start an embedded server. That makes the same war both deployable and executable, which is handy for local testing.
4Choosing a Compatible Tomcat
This is where many migrations fail. Spring Boot 3 is built on Spring Framework 6 and Jakarta EE 10, which renamed the servlet packages from javax.servlet to jakarta.servlet and requires Servlet 6.0. Tomcat 9 and earlier implement javax.servlet, so they cannot run a Boot 3 war at all; the deployment fails because the classes Spring needs do not exist in the server. For Boot 3 we need Tomcat 10.1 or later.
Spring Boot 4 moves on to Jakarta EE 11 and Servlet 6.1, which means Tomcat 11 (check the Boot 4 documentation for the exact supported versions). And the server must run on a Java version that Boot supports, Java 17 or later, so an old shared Tomcat on Java 11 needs its JVM upgraded too.
| Spring Boot | Servlet API | Tomcat | Minimum Java |
|---|---|---|---|
| 2.7 | javax, Servlet 4 | 9.0 | 8 |
| 3.x | jakarta, Servlet 6.0 | 10.1 or later | 17 |
| 4.x | jakarta, Servlet 6.1 | 11 (check your version) | 17 |
5Settings That No Longer Apply
With an external container, Boot does not create the web server, so every property that configures the embedded server is ignored. server.port does nothing: the port is defined by Tomcat's server.xml connector, often 8080 for all applications on that server. server.servlet.context-path does nothing either: the context path comes from the war's file name or the server's configuration, so orders.war is served at /orders. Thread pool, connection, compression and SSL settings under server.* belong to Tomcat's configuration now, and server.shutdown=graceful is replaced by Tomcat's own undeploy behaviour.
Application settings, such as datasources, logging levels and our own properties, still work as usual, and can come from environment variables or JNDI. Logging deserves a check: the external Tomcat has its own logging, and our application logs through Logback inside the web application, so we decide where its files go explicitly.
6Follow-up questions
Why does deploying a Boot 3 war on Tomcat 9 fail?
Tomcat 9 implements the javax.servlet API, while Spring Framework 6 and Boot 3 are compiled against jakarta.servlet. When Tomcat looks for initializers, it finds none it understands, or loading fails with missing jakarta classes, so the application never starts. The fix is Tomcat 10.1 or later; Tomcat's migration tool can convert old javax wars for Tomcat 10, but not the other way round.
Can the war still be run with java -jar?
Yes. Boot's repackaged war keeps the provided embedded Tomcat jars in WEB-INF/lib-provided, which an external server ignores but the Boot launcher uses. So java -jar orders.war starts with an embedded server, which is useful for local testing and for a later move to containers.
Can several Boot wars share one Tomcat safely?
They can, each in its own web application class loader, but they share the JVM's memory, threads and Java version, so one leaking application affects the others, and all must agree on upgrades. Static ThreadLocals and drivers registered by the application can also leak class loaders on redeploy. This coupling is the main reason teams move away from shared servers.
7Conclusion
In this answer, we deployed a Spring Boot 3 application as a war to an external Tomcat by setting the packaging to war, extending SpringBootServletInitializer and overriding configure() to point at the application class, and marking spring-boot-starter-tomcat as provided. We saw that the server must support Jakarta Servlet, Tomcat 10.1 or later for Boot 3, and that server.* settings such as server.port and the context path no longer apply because the external container controls them.
Open with
There are three changes and two things to check. First, I set the packaging to war in Maven, or apply the war plugin in Gradle. Second, the application class extends SpringBootServletInitializer and overrides configure to return builder.sources of the application class.
Then, if they want more
That works because the external Tomcat looks for a ServletContainerInitializer on the classpath; Spring's implementation finds our initializer, and it builds the SpringApplication and registers the DispatcherServlet with Tomcat's servlet context instead of starting an embedded server. I keep the main method so the IDE still works.
Third, spring-boot-starter-tomcat becomes provided, or providedRuntime in Gradle, so the embedded Tomcat jars are not in WEB-INF/lib; Boot puts them in lib-provided, so java -jar on the war still works locally.
The first check is the server version: Boot 3 uses the jakarta.servlet packages and Servlet 6.0, so it needs Tomcat 10.1 or later on Java 17 or later; a Tomcat 9 server cannot run it at all, and Boot 4 needs Tomcat 11.
The second check is configuration: server.port, the context path, thread pools and SSL settings no longer apply, because Tomcat's own configuration controls them. The context path comes from the war's name.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3, Spring Framework 6, Jakarta EE 10, Jakarta EE 11
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What changes do you need to deploy a Spring Boot 3 application as a war to an external...": https://scrivio-interview-library.netlify.app/spring-boot/packaging-and-deployment/9c53d02722/