Testing Spring MVC @ExceptionHandler method with Spring MVC Test

前端 未结 7 1822
悲&欢浪女
悲&欢浪女 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:28

    This is better:

    ((HandlerExceptionResolverComposite) wac.getBean("handlerExceptionResolver")).getExceptionResolvers().get(0)
    

    And do not forget to scan for @ControllerAdvice beans in your @Configuration class:

    @ComponentScan(basePackages = {"com.company.exception"})
    

    ...tested on Spring 4.0.2.RELEASE

提交回复
热议问题