在Spring中使用Struts2-Rest-Plugin

时间:2011-12-21 15:52:11

标签: spring struts2 struts2-spring-plugin

我开始在Spring应用程序中使用Struts2 Rest插件。 让我们从 struts.xml 开始:

<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.custom.i18n.resources" value="lang/messages" />
    <constant name="struts.ognl.allowStaticMethodAccess" value="true" />
    <constant name="struts.mapper.class" value="rest" />

    <package name="default">
        <action name="document" class="DocumentRestaction" />
    </package>
</struts>

然后在Spring中,我正在执行以下操作(以查看是否注入了String):

<bean name="DocumentRestaction" class="be.example.actions.DocumentRestaction">
    <property name="injected" value="Oh Hai" />
</bean>

我对网址POST发出了/documents个请求,并以create()方式结束,太棒了!在调试中,我的injected变量被注入。但是当我继续调试时,我得到以下异常:

4129 [http-8080-2] ERROR org.apache.struts2.rest.RestActionInvocation - Exception processing the result.
java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [DocumentRestaction]
    at org.apache.struts2.convention.ConventionsServiceImpl.determineResultPath(ConventionsServiceImpl.java:100)
    at org.apache.struts2.convention.ConventionUnknownHandler.determinePath(ConventionUnknownHandler.java:379)
    at org.apache.struts2.convention.ConventionUnknownHandler.handleUnknownResult(ConventionUnknownHandler.java:268)
    at com.opensymphony.xwork2.DefaultUnknownHandlerManager.handleUnknownResult(DefaultUnknownHandlerManager.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:227)
    at org.apache.struts2.rest.RestActionInvocation.executeResult(RestActionInvocation.java:221)
    at org.apache.struts2.rest.RestActionInvocation.processResult(RestActionInvocation.java:198)
    at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:146)
    at com.opensymphony.xwork2.DefaultActionProxy.execute(DefaultActionProxy.java:147)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: DocumentRestaction
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.struts2.util.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:111)
    at org.apache.struts2.convention.ConventionsServiceImpl.determineResultPath(ConventionsServiceImpl.java:98)
    ... 27 more

但是这个课程已被发现..(我最终在create),为什么这么说?最重要的是,我做错了什么?

我正在使用Spring v3.0.5,struts2-rest-plugin v2.3.1,struts2-core v2.3.1和struts2-spring-plugin 2.3.1

1 个答案:

答案 0 :(得分:0)

如果有人正在寻找解决方案,this文章可能有帮助。

虽然在您的applicationContext.xml中给出了示例代码中的遗漏,但请确保将“id”和“class”定义为控制器的完全限定类名:

   <bean id="com.mersoft.web.controller.TestController" class="com.mersoft.web.controller.TestController">
      <constructor-arg ref="testManager" />
   </bean>

希望有所帮助。哦,并且要清楚,您不必像先前评论中所建议的那样删除约定插件。