简体   繁体   English

StatefulJ框架使用的@RequestParam批注异常

[英]Exception on @RequestParam annotation used from statefulJ framework

I'm getting an exception like below when I try to get parameter from http request using spring(@RequestParam): 当我尝试使用spring(@RequestParam)从http请求获取参数时,出现如下异常:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.RuntimeException: java.lang.IllegalArgumentException: argument type mismatch
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.RuntimeException: java.lang.IllegalArgumentException: argument type mismatch
org.statefulj.framework.core.actions.MethodInvocationAction.execute(MethodInvocationAction.java:120)
org.statefulj.fsm.FSM.executeAction(FSM.java:228)
org.statefulj.framework.core.fsm.FSM.transition(FSM.java:110)
org.statefulj.fsm.FSM.onEvent(FSM.java:116)
org.statefulj.framework.core.fsm.FSM.onEvent(FSM.java:87)
org.statefulj.framework.core.model.impl.StatefulFSMImpl.onEvent(StatefulFSMImpl.java:74)
org.statefulj.framework.core.model.impl.FSMHarnessImpl.onEvent(FSMHarnessImpl.java:85)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl.access$001(JPAFSMHarnessImpl.java:30)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl$1.doInTransaction(JPAFSMHarnessImpl.java:52)
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl.onEvent(JPAFSMHarnessImpl.java:47)
statefulj.controller.StatefulJControllerMVCBinder.$_get_(StatefulJControllerMVCBinder.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.IllegalArgumentException: argument type mismatch
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.statefulj.framework.core.actions.MethodInvocationAction.invoke(MethodInvocationAction.java:149)
org.statefulj.framework.core.actions.MethodInvocationAction.invoke(MethodInvocationAction.java:139)
org.statefulj.framework.core.actions.MethodInvocationAction.execute(MethodInvocationAction.java:98)
org.statefulj.fsm.FSM.executeAction(FSM.java:228)
org.statefulj.framework.core.fsm.FSM.transition(FSM.java:110)
org.statefulj.fsm.FSM.onEvent(FSM.java:116)
org.statefulj.framework.core.fsm.FSM.onEvent(FSM.java:87)
org.statefulj.framework.core.model.impl.StatefulFSMImpl.onEvent(StatefulFSMImpl.java:74)
org.statefulj.framework.core.model.impl.FSMHarnessImpl.onEvent(FSMHarnessImpl.java:85)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl.access$001(JPAFSMHarnessImpl.java:30)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl$1.doInTransaction(JPAFSMHarnessImpl.java:52)
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
org.statefulj.framework.persistence.jpa.JPAFSMHarnessImpl.onEvent(JPAFSMHarnessImpl.java:47)
statefulj.controller.StatefulJControllerMVCBinder.$_get_(StatefulJControllerMVCBinder.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

But the thing is that I use @StatefulController and statefulJ framework( http://www.statefulj.org/ ). 但是问题是我使用@StatefulController和statefulJ框架( http://www.statefulj.org/ )。 When I use @RequestParam with @Controller annotation it works but in @StatefulController I'm getting exception. 当我将@RequestParam与@Controller注释一起使用时,它可以工作,但是在@StatefulController中,我遇到异常。 According to the official demo( https://github.com/statefulj/statefulj-framework-demo-mongo/blob/master/src/main/java/org/statefulj/webapp/controller/UserController.java ) this annotation should work in @StatefulController. 根据官方演示( https://github.com/statefulj/statefulj-framework-demo-mongo/blob/master/src/main/java/org/statefulj/webapp/controller/UserController.java ),此注释应该有效在@StatefulController中。

I don't know what I'm doing wrong. 我不知道我在做什么错。 Here is my code: 这是我的代码:

@StatefulController(
    clazz=Reservation.class,
    startState=Reservation.FREE,
    factoryId="reservationFactory")
public class StatefulJController
{
  public static final String HOMEPAGE_EVENT = "springmvc:/";
  public static final String RESERVE_EVENT = "springmvc:/reserve";

  @Transition(event=RESERVE_EVENT)
  public String startReservation(@RequestParam String quantity)
  {
    System.out.println(quantity);
    return "reserve";
  }
}

StatefulJ always passes in the Entity and Event on the first two parameters. StatefulJ始终在前两个参数上传递Entity和Event。

From the documentation: http://www.statefulj.org/framework/#define-your-transitions 从文档中: http : //www.statefulj.org/framework/#define-your-transitions

When a Transition is invoked, the StatefulJ Framework will call the associated method. 调用Transition时,StatefulJ Framework将调用关联的方法。 If the StatefulController is a Controller (vs a Domain Entity), then the first two parameters of the method are always: 如果StatefulController是一个控制器(相对于域实体),则该方法的前两个参数始终为:

Stateful Entity 有状态实体

The Event 事件

So your method should look like: 因此,您的方法应如下所示:

public String startReservation(Reservation reservation, String event, @RequestParam String quantity)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM