升级Spring 5.3后WebSphere部署Spring MVC访问报SRVE0190E文件未找到错误
问题原因及解决步骤
根因分析
- 你的Spring XML配置文件中的schema版本仍然停留在3.1,和升级后的Spring 5.3版本不兼容。Spring 5.3对过时的schema定义、HandlerMapping的加载优先级逻辑做了调整,导致你自定义的SimpleUrlHandlerMapping没有生效,请求最终被
DefaultServletHttpRequestHandler处理,直接去查找静态文件/index.html,找不到就抛出对应异常。 - Spring 5.3中默认注册的HandlerMapping优先级比你自定义的SimpleUrlHandlerMapping更高,你配置的路径映射规则没有被优先匹配,这也是你删除或保留
index.html映射配置都不影响报错结果的核心原因。 - 你配置的
<mvc:default-servlet-handler/>会兜底处理所有没有匹配到Controller的请求,直接转发给应用服务器的默认Servlet处理静态资源,如果你并没有实际存在的静态index.html文件,自然会报文件找不到。
修复方案
步骤1:更新XML schema版本
把configuration.xml里所有的3.1版本xsd替换成不带版本号的格式,Spring会自动匹配当前版本的schema:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd"
步骤2:调高自定义SimpleUrlHandlerMapping的优先级
给你定义的SimpleUrlHandlerMapping Bean添加order属性,值越小优先级越高,设置为0即可保证你的自定义路径映射优先被匹配:
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <!-- 新增优先级配置 --> <property name="order" value="0"/> <!-- 原有其他配置保持不变 --> <property name="urlMap"> ... </property> </bean>
步骤3:验证Controller配置
检查homeController是否加了@Controller注解,以及对应的请求处理方法可以正常接收路径请求即可。
步骤4:静态资源适配(可选)
如果你的项目中确实存在静态的html文件,可补充添加静态资源映射配置:
<mvc:resources mapping="/**/*.html" location="/"/>
内容的提问来源于stack exchange,提问作者user3067524
相关产品推荐
相关产品推荐

