You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Spring Framework到5.3出现No adapter for handler异常求助

问题根因定位
  • 配置映射的Bean ID不匹配:XML中定义的UploadFormController的id是uploadFormController,但SimpleUrlHandlerMapping的mappings配置中写的是starSiSpreadsheetUploadFormController,名称完全不匹配,Spring找不到对应的处理类。
  • 注解控制器方法缺少请求映射注解:使用@Controller的注解式控制器需要在处理方法上标注@RequestMapping/@GetMapping/@PostMapping注解才能被Spring 5默认的RequestMappingHandlerAdapter识别,你现有代码中的onSubmit、referenceData方法都没有对应注解,Spring找不到适配的处理逻辑就会抛出无适配器错误。
  • XML Schema版本不兼容:所有Spring schema的版本都还是3.1版本,和升级后的5.3版本不匹配,可能引发未知的配置解析异常。
  • 开发规范不兼容:现有代码还是旧版Spring MVC继承SimpleFormController的写法,新版注解式控制器已经不识别onSubmit、referenceData这类固定命名的约定方法,需要按注解规则调整。
修复步骤
  1. 调整HandlerMapping配置:你已经在控制器类上添加了@RequestMapping("/upload.html"),组件扫描会自动完成路径映射,直接删除手动配置的SimpleUrlHandlerMapping即可。如果要保留手动配置,将mappings配置中的prop值改为正确的Bean id uploadFormController,同时注意避免和注解路径产生冲突。
  2. 补充方法请求映射注解:根据请求的HTTP方法给处理方法添加对应注解,示例调整如下:
// GET请求用于页面初始化,返回参考数据
@GetMapping
protected Map referenceData(HttpServletRequest request) throws Exception {
    // 原有逻辑不变
}

// POST请求用于表单提交
@PostMapping
protected String onSubmit(HttpServletRequest request, HttpServletResponse response, @ModelAttribute SpreadsheetUpload bean, BindingResult errors) throws Exception {
    // 原有逻辑不变,把类注入的SpreadsheetUpload改为方法参数接收,避免线程安全问题
}
  1. 更新XML Schema版本,把所有xsi:schemaLocation里的-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"
  1. 如果你不想调整现有方法结构,要兼容旧版Controller接口的写法,手动注册SimpleControllerHandlerAdapter到Spring容器即可(mvc:annotation-driven默认不会注册该适配器):
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

同时需要让UploadFormController实现Controller接口或者继承旧版的SimpleFormController抽象类。

额外注意

你当前将SpreadsheetUpload作为类属性自动注入,Spring默认Bean是单例模式,多请求场景下会出现线程安全问题,建议改为方法参数用@ModelAttribute注解绑定请求数据。

内容的提问来源于stack exchange,提问作者user3067524

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 17:15:03