spring boot tomcat url路径不分区大小写


第一种方法修改程序,如果修改程序无效,可以试着修改tomcat的配置。
修改程序
在程序中添加一个自定义的webConfig.java类
import org.springframework.context.annotation.Configuration; import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configurePathMatch(PathMatchConfigurer configurer) { AntPathMatcher matcher = new AntPathMatcher(); matcher.setCaseSensitive(false); configurer.setPathMatcher(matcher); } }
修改配置
tomcat版本为:tomcat 7
在 webapps 下有一个 ROOT 项目。
此项目要路径不分区大小写,则需要在对应项目的 META-INF 下添加文件 context.xml
context.xml 内容:
<?xml version="1.0" encoding="UTF-8"?> <Context path="/ROOT" allowLinking="true"> </Context>
注意:path 后面是 项目名称
说明:
不分区大小写,在 tomcat 7 版本下,是配置 Context 节点的 allowLinking 属性。
官方文档:https://tomcat.apache.org/tomcat-7.0-doc/config/context.html
寻找答案的方法:
google 搜索 tomcat 7 case insensitive 就会搜到对应的官方文档,还有其他答案,比如:
https://stackoverflow.com/questions/315093/configure-symlinks-for-single-directory-in-tomcat
需要注意的是不同的tomcat版本的设置还不一样
tomcat 6 是设置 caseInsensitive 属性的
tomcat 8 下是修改文件 apache-tomcat-8.5.34\conf\context.xml
在 Context 节点下 添加
<Resources allowLinking="true" />
<Context> <!-- Default set of monitored resources. If one of these changes, the --> <!-- web application will be reloaded. --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <Resources allowLinking="true" /> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> </Context>
Resources 节点还可以设置其他属性
<Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000" />
官网文档:https://tomcat.apache.org/tomcat-8.0-doc/config/resources.html
修改后,如果没有效果,则重启 tomcat 即可。
*昵称:
*邮箱:
个人站点:
*想说的话: