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

Struts 2.3.37迁移至2.5.33时Tomcat启动报错NoSuchMethodError

Struts 2.3.37 迁移至 2.5.33 启动报错:NoSuchMethodError 解决方案

错误根源

这个错误是Struts 2.5 与 Tiles 组件版本不兼容导致的:

  • Struts 2.3 适配的是 Tiles 2.x 版本
  • Struts 2.5 已全面切换为适配 Tiles 3.x 版本,旧的 Tiles 2.x 中BasicTilesContainer类不存在setApplicationContext(Lorg/apache/tiles/request/ApplicationContext;)V方法,启动时触发该错误。

解决步骤

  • 移除旧依赖:删除项目中所有 Tiles 2.x 相关的 jar 包(如tiles-core、tiles-api、tiles-jsp等 2.x 版本)
  • 添加兼容依赖:
    若用 Maven,直接引入 Struts 2.5.33 的 Tiles 插件,它会自动带入适配的 Tiles 3.x 依赖:
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-tiles-plugin</artifactId>
        <version>2.5.33</version>
    </dependency>
    
    手动管理 jar 的话,需引入 Tiles 3.x 核心包:tiles-api-3.x.jar、tiles-core-3.x.jar、tiles-jsp-3.x.jar、tiles-request-api-1.x.jar、tiles-request-servlet-1.x.jar
  • 更新配置文件:将tiles.xml的 DTD 声明替换为 Tiles 3.x 版本:
    <!DOCTYPE tiles-definitions PUBLIC
        "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
        "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
    
  • 清理缓存并重新部署:
    • Maven 执行mvn clean install
    • 手动部署的话,清空 Tomcat 对应项目WEB-INF/lib下的旧 jar,重新部署

验证

重启 Tomcat 9.0.45,确认StrutsTilesListener初始化成功,无NoSuchMethodError抛出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 08:44:55