Struts2 2.5版本执行请求不执行指定method

报错 Wrong method was defined as an action method: index (Action类里面没有定义index这个方法)

错误原因 :

按以往的理解 为了实现项目的零配置,采用struts2的注解方式进行配置,会直接调getHelloWorld方法。
那么为何会报错呢?
看了Struts2的调用全过程,发现其实调用mapper的时候 是直接指向org.apache.struts2.dispatcher.mapper.Restful2ActionMapper 而不是DefaultActionMapper,
这样就导致了调用到rest里面的
if (mapping.getMethod() == null) {
if (lastSlashPos == actionName.length() - 1) {
if (isGet(request)) {
mapping.setMethod(“index”);
} else if (isPost(request)) {
mapping.setMethod(“create”);
}
}
所以直接报NoSuchMethodException。
可配置文件中没有配置支持Restful2ActionMapper。
那是否struts2.3.24中jar包有插件直接支持呢?
果然发现了:struts2-rest-plugin-2.3.24.jar 这个包中的:struts-plugin.xml

<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="rest" class="org.apache.struts2.rest.RestActionProxyFactory" />
这个导致了Restful2ActionMapper的调用。

解决方法:删除struts2-rest-plugin-xxx.jar

原文:https://blog.csdn.net/yzk2356911358/article/details/78568028

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值