Struts2 Rest - 不允许采取行动的方法

时间:2018-02-16 14:47:49

标签: rest struts2 struts2-rest-plugin

我正在使用Struts-2.5.14.1和Struts rest插件。 除了自定义方法之外,Eveything似乎工作得很好。 索引,show和其他默认方法都有效。 但是当我提供一些不同的自定义方法时,它似乎无法工作并抛出错误。

  

com.opensymphony.xwork2.config.ConfigurationException:不允许使用方法发送操作消息!       在com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:203)〜[struts2-core-2.5.14.1.jar:2.5.14.1]       在com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:76)〜[struts2-core-2.5.14.1.jar:2.5.14.1]       在org.apache.struts2.rest.RestActionProxyFactory.createActionProxy(RestActionProxyFactory.java:50)〜[struts2-rest-plugin-2.5.14.1.jar:2.5.14.1]       在org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)[struts2-core-2.5.14.1.jar:2.5.14.1]

2 个答案:

答案 0 :(得分:0)

REST插件按惯例使用映射HTTP方法到java方法。

其他方法可以在非严格模式的rest action mapper中映射。

如果您想了解更多相关信息,请阅读this answer。

答案 1 :(得分:0)

将此代码添加到struts.xml中,然后尝试:

<package ...>
    <global-allowed-methods>regex:.*</global-allowed-methods>
    <action ...>
        ...
    </action>
</package>