DispatcherServlet and web.xml in Spring Boot

  1. Yes, spring boot no longer relies on xml configuration and it configures an equivalent to the dispatcher servlet automatically. You can follow the following link to see how to register your filters: How to add a filter class in Spring Boot?
  2. If you use maven and not gradle, the only XML in your spring boot project should be pom.xml. The way to go with spring boot is moving all your xml configuration, web.xml etc to spring boot's auto configuration + your java configuration.

Spring boot works very good when you do everything in java configuration and follow its principals. From my experience with it, when you start merging XML configuration and the legacy spring it starts breaking the auto configuration process and its much better to try as much as you can to comply with the new spring boot best practices.


  1. You can keep your web.xml, but it needs to add

    <listener>
         <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
    </listener> 
    

    in web.xml. And, required dependency of pom.xml.

  2. All listener classes, filters converts in Java class. This class would be @Configuration.

  3. If you have an interceptor, that can be moved to configuration class.