Testing Spring MVC @ExceptionHandler method with Spring MVC Test

前端 未结 7 1828
悲&欢浪女
悲&欢浪女 2020-12-04 20:56

I have the following simple controller to catch any unexpected exceptions:

@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(Throwa         


        
7条回答
  •  鱼传尺愫
    2020-12-04 21:39

    Since you are using stand alone setup test you need to provide exception handler manually.

    mockMvc= MockMvcBuilders.standaloneSetup(adminCategoryController).setSingleView(view)
            .setHandlerExceptionResolvers(getSimpleMappingExceptionResolver()).build();
    

    I had same problem a few days back, you can see my problem and solution answered by myself here Spring MVC Controller Exception Test

    Hoping my answer help you out

提交回复
热议问题