Spring Boot
web.xml
deployment
Java
application configuration

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.

Practice system design

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.

java
1import org.springframework.boot.SpringApplication;
2import org.springframework.boot.autoconfigure.SpringBootApplication;
3
4@SpringBootApplication
5public class DemoApplication {
6    public static void main(String[] args) {
7        SpringApplication.run(DemoApplication.class, args);
8    }
9}

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:

java
1import jakarta.servlet.Filter;
2import org.springframework.boot.web.servlet.FilterRegistrationBean;
3import org.springframework.context.annotation.Bean;
4import org.springframework.context.annotation.Configuration;
5
6@Configuration
7public class WebConfig {
8    @Bean
9    public FilterRegistrationBean<Filter> loggingFilter() {
10        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
11        bean.setFilter((request, response, chain) -> chain.doFilter(request, response));
12        bean.addUrlPatterns("/*");
13        return bean;
14    }
15}

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.

java
1import org.springframework.boot.builder.SpringApplicationBuilder;
2import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
3
4public class ServletInitializer extends SpringBootServletInitializer {
5    @Override
6    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
7        return application.sources(DemoApplication.class);
8    }
9}

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.xml because older servlet apps did.
  • Adding web.xml to 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.xml only when a legacy environment or migration scenario truly requires it.
  • For new Boot applications, Java-based configuration is the standard approach.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.