Reputation: 31
I have been using the below property in the application.properties
file with spring-boot.version 1.5.6.RELEASE
without any issues.
server.servletPath=/*
This was a workaround to enable a method in a library class which uses the function getPathInfo()
of javax.servlet.http.HttpServletRequest
to get a valid value instead of null
.
I had to go with this workaround since there is no support of that library jar anymore.
This workaround started failing when I upgraded my application to spring-boot.version 2.1.7.RELEASE
server.servletPath
is changed to spring.mvc.servletPath
from Spring Boot 2 onwards.
I tried setting the below property and it did not work
spring.mvc.servletPath=/*
I also tried the below function in my configuration class and it did not work.
@Bean
public DispatcherServletRegistrationBean dispatcherServletRegistration(
DispatcherServlet dispatcherServlet,
ObjectProvider<MultipartConfigElement> multipartConfig) {
DispatcherServletRegistrationBean registration = new DispatcherServletRegistrationBean(
dispatcherServlet, "/*");
registration.setName("dispatcherServlet");
registration.setLoadOnStartup(-1);
multipartConfig.ifAvailable(registration::setMultipartConfig);
return registration;
}
Could you please provide a working solution for this property using spring-boot.version 2.1.7.RELEASE
?
Thanks, Dhinu
Upvotes: 1
Views: 2341
Reputation: 3818
The correct setting for newer spring versions is:
spring.mvc.servlet.path=/some/path
This changes the mapping of the DispatcherServlet, so all resources served by spring are mapped to this path.
If you set:
server.servlet.contextPath=/some/path
The whole web context is changed.
The main difference is that setting the dispatcher servlet path allows you to register additional servlets on other paths while with context path set, spring boot's tomcat can only serve content below that context path.
Upvotes: 2
Reputation: 5968
Use the following config property on latest spring boot version:
server.servlet.contextPath=/*
Upvotes: 1