Struts2 2.5版本执行index 不执行指定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" />
 <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="rest" class="org.apache.struts2.rest.RestActionMapper" />
    <constant name="struts.mapper.class" value="rest" />
这个导致了Restful2ActionMapper的调用。

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


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

茅十八呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值