@BeforeClass
 public static void setupOnce() {
   ExceptionHandlerExceptionResolver r = new ExceptionHandlerExceptionResolver();
   r.afterPropertiesSet();
   RESOLVER_COUNT = r.getArgumentResolvers().getResolvers().size();
   HANDLER_COUNT = r.getReturnValueHandlers().getHandlers().size();
 }
 @Bean
 public ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver() {
   ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver =
       new ExceptionHandlerExceptionResolver();
   exceptionHandlerExceptionResolver.setOrder(1);
   exceptionHandlerExceptionResolver.setMessageConverters(
       Lists.newArrayList(getJson2MessageConverter()));
   return exceptionHandlerExceptionResolver;
 }
  @Override
  protected List<? extends HandlerExceptionResolver> initHandlerExceptionResolvers() {
    ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver();
    if (messageConverters != null) {
      exceptionResolver.setMessageConverters(messageConverters);
    }
    exceptionResolver.afterPropertiesSet();

    List<HandlerExceptionResolver> resolvers = new ArrayList<HandlerExceptionResolver>();
    resolvers.add(exceptionResolver);
    resolvers.add(new ResponseStatusExceptionResolver());
    resolvers.add(new DefaultHandlerExceptionResolver());

    return resolvers;
  }
  /**
   * Register Exception Handlers with the Standalone MockMvc instance.
   *
   * @return the excepation handler resolver
   */
  protected ExceptionHandlerExceptionResolver createExceptionResolver() {
    ExceptionHandlerExceptionResolver exceptionResolver =
        new ExceptionHandlerExceptionResolver() {
          protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
              HandlerMethod handlerMethod, Exception exception) {
            Method method =
                new ExceptionHandlerMethodResolver(GlobalExceptionHandler.class)
                    .resolveMethod(exception);
            return new ServletInvocableHandlerMethod(new GlobalExceptionHandler(), method);
          }
        };
    exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    exceptionResolver.afterPropertiesSet();
    return exceptionResolver;
  }
  private ExceptionHandlerExceptionResolver createExceptionResolver(Object handler) {

    ExceptionHandlerExceptionResolver resolver =
        new ExceptionHandlerExceptionResolver() {

          @Override
          protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
              HandlerMethod handlerMethod, Exception ex) {

            Method m = new ExceptionHandlerMethodResolver(handler.getClass()).resolveMethod(ex);
            return new ServletInvocableHandlerMethod(handler, m);
          }
        };
    resolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    resolver.afterPropertiesSet();
    return resolver;
  }
 @Bean
 public ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver() {
   ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
   resolver.setMessageConverters(HttpMessageConverterUtils.getDefaultHttpMessageConverters());
   return resolver;
 }