我一直在spring-boot.version 1.5.6.RELEASE中使用application.properties文件中的以下属性,没有任何问题。
server.servletPath=/*这是一种变通方法,用于启用库类中的方法,该方法使用javax.servlet.http.HttpServletRequest的函数getPathInfo()来获取有效值,而不是null。
由于不再支持该库jar,我不得不采用这种变通方法。
当我将应用程序升级到spring-boot.version 2.1.7.RELEASE时,此解决方法开始失败
从Spring Boot2开始,server.servletPath被更改为spring.mvc.servletPath。
我尝试设置下面的属性,但不起作用
spring.mvc.servletPath=/*我还在我的configuration类中尝试了下面的函数,但它不起作用。
@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;
}您能为这个属性提供一个使用spring-boot.version 2.1.7.RELEASE的可行解决方案吗
谢谢,Dhinu
发布于 2020-03-30 23:51:46
较新spring版本的正确设置为:
spring.mvc.servlet.path=/some/path这会更改DispatcherServlet的映射,因此spring服务的所有资源都映射到此路径。
如果设置:
server.servlet.contextPath=/some/path整个网络环境都被改变了。
主要区别在于,设置dispatcher servlet路径允许您在其他路径上注册其他servlet,而设置了上下文路径后,spring boot的tomcat只能提供该上下文路径下的内容。
发布于 2019-08-31 12:57:26
在最新的spring boot版本上使用以下配置属性:
server.servlet.contextPath=/*https://stackoverflow.com/questions/57733555
复制相似问题