2017-06-30 7 views
0

SpringMockMvcを使用していて、コントローラに私は@ExceptionHandlerを持っています。 postリクエストを呼び出すと、以下のエラーが表示されます。ExceptionHandlerを使用すると、Spring mockMvcがエラーをスローする

Failed to invoke @ExceptionHandler method: public org.springframework.http.ResponseEntity<com.xx.xxx> com.xx.xx.handleException(java.lang.Throwable,org.eclipse.jetty.server.Request) 
java.lang.IllegalStateException: Current request is not of type [org.eclipse.jetty.server.Request]: [email protected] 
     at org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver.resolveArgument(ServletRequestMethodArgumentResolver.java:97) 

私は、要求がorg.springframework.mock.web.MockHttpServletRequestorg.eclipse.jetty.server.Requestのサブタイプではないという理由だけで、働くことができませんでした、そのタイプのorg.springframework.mock.web.MockHttpServletRequest

答えて

1

ある場合@ExceptionHandlerを扱うことができない理由はわかりません。したがって、org.eclipse.jetty.server.Requestのパラメータに対して、SpringがMockHttpServletRequestのインスタンスを提供することは不可能です。

handleException()メソッドの2番目のパラメータのタイプをjavax.servlet.http.HttpServletRequestに変更する必要があります。

+0

ありがとう、それが問題を解決しました。 – tabiul

関連する問題