Is web.xml required to deploy a spring boot application
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
No, web.xml is not required for a typical Spring Boot application. Spring Boot was designed to eliminate much of the old servlet XML configuration by using embedded servers, auto-configuration, and Java-based registration instead of a traditional deployment descriptor.
Why traditional servlet apps used web.xml
Before Spring Boot, Java web applications were often packaged as WAR files and deployed to an external servlet container such as Tomcat. The web.xml file described things like:
- servlet mappings
- filters
- listeners
- welcome pages
- context parameters
That file was central to the old deployment model because the container read it to know how the application should start.
Why Spring Boot usually does not need it
Spring Boot changes the deployment model in two major ways:
- it can run with an embedded servlet container
- it prefers Java configuration and annotations over XML deployment descriptors
A normal Boot application starts from a main method.
That is enough for many applications. There is no web.xml because Spring Boot configures the servlet environment programmatically.
Filters, servlets, and listeners can be registered in code
What used to live in web.xml can usually be expressed with beans or annotations.
For example, a filter can be registered with a bean:
This is the Spring Boot style replacement for a lot of old deployment-descriptor configuration.
WAR deployment still usually does not require web.xml
Even if you package a Spring Boot app as a WAR and deploy it to an external servlet container, you still usually do not need web.xml. Instead, you extend SpringBootServletInitializer.
That class bridges Boot into the external container without needing an XML deployment descriptor.
When web.xml might still appear
There are edge cases where a web.xml file can still exist:
- migration from an older non-Boot application
- a legacy container or policy that expects descriptor-based setup
- coexistence with older libraries that were built around descriptor configuration
Even then, it is usually not required by Spring Boot itself. It is present because of legacy integration constraints.
Prefer Boot-native configuration unless a legacy requirement forces otherwise
If you are starting a new Boot project, adding web.xml generally adds ceremony without adding value. Boot-native configuration is easier to test, easier to refactor, and better aligned with how the framework expects applications to be structured.
The more interesting question is not "can I still use web.xml?" but "what old requirement is making me want it?"
Common Pitfalls
- Assuming every Java web application still needs a
WEB-INF/web.xmlbecause older servlet apps did. - Adding
web.xmlto a new Boot app just to recreate configuration that Boot already handles. - Forgetting that WAR deployment to an external container can still be Boot-native with
SpringBootServletInitializer. - Mixing legacy XML configuration and Boot auto-configuration without understanding which mechanism owns each setting.
- Blaming Spring Boot when the real requirement comes from an old container or migration constraint.
Summary
- A normal Spring Boot application does not require
web.xml. - Boot replaces most old servlet descriptor configuration with code and auto-configuration.
- Even external-container WAR deployments usually work without
web.xml. - Use
web.xmlonly when a legacy environment or migration scenario truly requires it. - For new Boot applications, Java-based configuration is the standard approach.
Related reading
- Is x-Protostream encoding supported in Keycloak version 21.x
- Issue in establishing connection with Rabbit MQ
- Issue when trying to delete VPC and Network Interface
- Issue with log4J (1.2.17 version) while renaming Kafka log files on Windows
- Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop
- Iterating through a list in reverse order in java
- Issues with stability with Kubernetes cluster before adding networking
- Issuing certificate as Secret does not exist

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.