The DefaultServlet is registered by default and mapped to / but in the vast majority of Boot apps this is overridden by the DispatcherServlet which is also mapped to /. When overridden like this the registration is pointless as the servlet will never be used. To avoid wasting memory and CPU cycles, we should change the default of server.servlet.register-default-servlet to false and document that you can set it to true to reinstate the previous behaviour in apps that were using it.
Comment From: mdiskin
I'm good with this so long as we retain server.servlet.context-path functionally.
We use spring boot/containers to migrate off appservers and the context-path allow for load balancer smart rules on host:port without rewriting the uri.
Comment From: philwebb
@mdiskin We're not planning to break that functionality. A lot of user rely on it.
Comment From: wilkinsona
Users will need to enable the default servlet if they are:
- Using JSPs
- Using Jersey configured as a filter and the default servlet was previously the servlet at the end of the filter chain
This list probably isn't exhaustive but those are the two identified by Boot's test suite.
Comment From: wtfiwtz
Could this impact on loading static resources from the src\main\webapp directory of a Spring Boot application? I've attempted to register a new static resource handler for /** => / but it doesn't seem to make any difference.
We have a IBM WebSphere app that was ported to Spring Boot and the .css file loading is now broken on Spring Boot 2.4.1/2, but was okay on 2.3.8. Javascript is loaded through JAWR so most other functionality stays the same.
@Configuration
public class ApplicationConfig implements WebMvcConfigurer
{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/path/**").addResourceLocations("/path/");
registry.addResourceHandler("/**").addResourceLocations("/");
}
}
There is already a registration for /** (confirmed with hasResourceHandler( )
Cheers, Nigel
Comment From: wtfiwtz
I added server.servlet.register-default-servlet=true to the application.properties file and this seems to have fixed it.
Cheers!