首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我在struts2+spring3项目中添加struts2-rest-plugin时,struts操作没有采用默认的方法(执行)。

当我在struts2+spring3项目中添加struts2-rest-plugin时,struts操作没有采用默认的方法(执行)。
EN

Stack Overflow用户
提问于 2013-09-24 05:31:49
回答 2查看 2.3K关注 0票数 0

我正在尝试使用struts2创建restful服务。当我在依赖项struts中添加struts2-rest-plugin时,动作没有采用默认的方法(Execute),.It正在寻找create()或index()方法。

struts2 2-惯例-插件和支柱2-rest-插件

代码语言:javascript
复制
<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts.version}</version>
</dependency>
<dependency>
             <groupId>org.apache.struts</groupId>
             <artifactId>struts2-rest-plugin</artifactId>
             <version>${struts.version}</version>
</dependency>

我在struts.xml中有所有这些常量

代码语言:javascript
复制
    <constant name="struts.devMode" value="false" />
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <constant name="struts.action.extension" value="action," />
    <constant name="struts.objectFactory" value="spring" />
    <constant name="struts.custom.i18n.resources" value="ApplicationResources,errors,global" />
    <constant name="struts.multipart.maxSize" value="2097152" />
    <constant name="struts.ui.theme" value="css_xhtml" />
    <constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/" />
    <constant name="struts.enable.SlashesInActionNames" value="true" />
    <constant name="struts.convention.action.disableScanning" value="true" />
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
   <constant name="struts.convention.package.locators" value="controller"/> 
   <constant name="struts.convention.action.suffix" value="Controller"/> 
   <constant name="struts.convention.action.mapAllMatches" value="false"/>
   <constant name="struts.convention.default.parent.package" value="rest-default"/>

当我执行web项目时,我会得到错误。

代码语言:javascript
复制
ERROR [tomcat-http--34] Dispatcher.error(38) | Exception occurred during processing request: com.vxl.appanalytix.webapp.action.LoginAction.create()
java.lang.NoSuchMethodException: com.vxl.appanalytix.webapp.action.LoginAction.create()
    at java.lang.Class.getMethod(Class.java:1655)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
    at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:138)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
    at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:138)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
    at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:138)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

我的项目有用于依赖性管理的spring,包括使用spring,我们计划使用struts2 2。我尝试使用spring服务,但是我得到了一些dispacher错误,所以我转到了struts2-REST插件。在这里,我作为服务实现的控制器类分别具有类似于HTTP和PUT的index()和create()方法。其余插件到底是如何工作的。

EN

回答 2

Stack Overflow用户

发布于 2013-09-24 06:43:06

请阅读docs 1,如果您想将普通web应用程序与rest服务混合使用,请考虑使用struts.rest.namespace 3将所有rest端点移动到专用名称空间中。

1

2

3

票数 2
EN

Stack Overflow用户

发布于 2016-03-03 18:59:10

使用struts2-rest插件以及convention-plugin意味着您的动作类不再将execute方法作为默认方法。实际上,您可能没有execute方法,而且仍然有一个有效的REST控制器。

convention-plugin定义了URL映射到类的方式。这里清楚地解释了这一点:http://struts.apache.org/docs/convention-plugin.html

而且,struts.rest.namespace-approach并不适合我。不知怎么的,Struts没有这样做。相反,我做了以下几件事:

代码语言:javascript
复制
<constant name="struts.convention.default.parent.package" value="myRestPackage"/>
<package name="myRestPackage" extends="rest-default" namespace="/rest"/>

这样,我就让Struts觉得REST服务调用的名称空间是/rest

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18973632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档