添加@ControllerAdvice后报错 Failed to invoke @ExceptionHandler method

首先。单独使用ControllerAdvice 无法正常工作。需要配合@EnableWebMvc 使用。

@ControllerAdvice

@EnableWebMvc

pulbic class ExceptionControllerAdvice{

  @ExceptionHandler(NotFoundException.class)

  @ResponseBody

  public Map<String,Object> notFoundExc(NotFoundException exc,HttpServletRequest req){

  .......

  }

}

在启动之异常处理报错。

错误信息:

七月 04, 2016 11:00:11 上午 org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver doResolveHandlerMethodException

严重: Failed to invoke @ExceptionHandler method: public java.util.Map<java.lang.String, java.lang.Object> com.dooioo.modelException.ExceptionControllerAdvice.notFoundError(com.dooioo.modelException.NotFoundException,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:134)

at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:101)

at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:185)

at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)

at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:362)

at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:60)

at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:138)

at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1183)

at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1020)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

xx-servlet.xml中已经配置了messageconverter处理器了。

<bean id="dyMessageConverter" class="com.dooioo.web.converter.DyMappingJacksonHttpMessageConverter"/>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<!-- spring绑定时处理函数 -->

<property name="webBindingInitializer">

<bean class="com.dooioo.init.DefaultBindingInitializer"/>

</property>

<property name="messageConverters">

<list>

<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>

<ref bean="dyMessageConverter"/>

</list>

</property>

<property name="requireSession" value="false"/>

<property name="order" value="0"/>

</bean>

上网翻了一遍资料 没有结果。

最后发现和在xml中的顺序有关系。<mvc:annotation-driven/>。

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 适配器必须声明在<mvc:annotation-driven />之前,否则不能正常处理参数类型的转换

到此问题解决。

时间: 2024-10-25 19:54:57

添加@ControllerAdvice后报错 Failed to invoke @ExceptionHandler method的相关文章

com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method

查看了网友们的错误原因, 需要进行实例化的类没有进行实例化,具体没有实例化的类会在错误信息中显示,在错误信息中搜索"Serializable"即可找到将其实现序列化可消除错误. 是在使用Dubbo提供服务是在主机上启动了虚拟机的网络,在Windows中具体可以,在运行中输入"CMD"在CMD窗口中输入"ifconfig"命令查看,如果有其他除本地的网络链接,通过命令或者将其手动禁止,再启动Dubbo服务可以解决问题. 防火墙对应端口没有开启 我这

xib添加手势后报错:-[UITapGestureRecognizer setFrame:]: unrecognized selector sent to instance xxx

主要原因如下: + (instancetype)mineHeaderView { return [[NSBundle mainBundle] loadNibNamed:@"DDMineHeaderView" owner:nil options:nil].lastObject; } 添加手势后, 以上的创建对象方法就不可以通过lastObject来获取了, 因为获取到的是最后添加的手势对象, 所以才会出现这个错误 解决方法: 将lastObject改为firstObject即可..

关于dubbo调度时出现Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method insertTestTb in the service cn.cuibusi.core.service.TestTbService.的解决办法

在用dubbo跨项目调度service时出现如下错误: 错误原因:pojo没有实现序列化 今天刚好复习了序列化,在分布式环境下,当进行远程通信时,无论是何种类型的数据,都会以二进制的形式在网络上进行传送.序列化是一种将对象,以一连串的字节描述的过程,用于解决在对对象流进行读写时所引发的问题. 解决方法:在pojo实现序列化接口即可

dubbo异常: Failed to invoke the method getXXXX in the service 异常解决方案

解决方案: 1.将dubbo.registry.address修改为正确地址 2.遇到该异常可能还有其他情况: 实体类没有实现java.io.Serializable,因为是远程服务,所有必须实现序列化接口 暂时就是这么些,欢迎大家补充! 原文地址:https://www.cnblogs.com/vycz/p/12078716.html

MFC 错误异常,用vs添加资源并为资源定义类后报错:error C2065 : 未声明的标识符

添加了一个Dialog资源,修改了ID之后右击资源添加了一个类,在类里面有一个成员变量: // 对话框数据    enum { IDD = IDD_GETIN }; 而在编译过程中出现报错,错误代号是error C2065 : 未声明的标识符,我的第一反应是为什么我没通过手动添加资源而是通过VS添加都会出现这种情况呢,我想应该是其它地方错误导致此报错吧,但是却没想过,此类错误往往是因为没有包含某个头文件而引起的. 最后我是这样解决的:添加了一个#include"Resource.h"

解决添加swagger后项目报错 Failed to start bean &#39;documentationPluginsBootstrapper&#39;

添加swagger后项目报错 Failed to start bean 'documentationPluginsBootstrapper' 因为swagger依赖google的guava,而当前项目的guava版本与之不匹配,将当前项目的guava版本升到swagger子依赖的guaba版本相同即可解决 原文:https://blog.csdn.net/xiaofanren1111/article/details/83011454 解决添加swagger后项目报错 Failed to star

Git添加远程报错:remote origin already exists.

在本地创建了一个Git仓库,如何在Github创建一个Git仓库,并且让这两个仓库进行远程同步,这样Github上的仓库既可以作为备份仓库,还可以通过该仓库进行多人协作. 1.登录github,建立一个新的仓库 2.添加仓库名字 3根据Github的提示,在本地的learngit仓库下运行命令 1 $ git remote add origin [email protected]:zhanghuming/learngit.git 4.把本地库的所有内容推送到远程库上 1 $ git push -

Hibernate卡住,然后报错java.sql.SQLException: Unknown system variable &#39;language&#39;异常

启动应用的时候会卡在: 08:22:58,221 DEBUG IntegratorServiceImpl:46 - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator]. 08:22:58,226 DEBUG IntegratorServiceImpl:46 - Adding Integrator [org.hibernate.secure.spi.JaccIntegrator]. 08:22:

WCF Failed to invoke the service. Possible causes: The service is offline or inaccessible

今天写WCf 时遇到如下报错: 调试过程发现,各个过程都无异常,但是返回给调用端数据时出现如下错误. Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace