添加@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...........(省略。。。。)
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 />之前,否则不能正常处理参数类型的转换
到此问题解决。
添加@ControllerAdvice后报错 Failed to invoke @ExceptionHandler method的更多相关文章
- SpringBoot项目中的全局异常处理器 Failed to invoke @ExceptionHandler method
文件下载代码 @RequestMapping(value = { "/data/docking/picture/{id}/{empi}" }) public JsonApi pic ...
- dubbo+zookeeper报错:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method可能的错误原因有三个前两个是从网上摘得, 第三个是自己解决的 1.需要进行 ...
- com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findUserByUserNo in the service wusc.edu.facade.user.service.PmsUserFacade.
017-04-25 10:55:30,505 INFO [AbstractRegistry.java:302] : [DUBBO] Register: consumer://192.168.1.101 ...
- [TODO]com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
异常信息如下: 2018-10-30 20:00:50.230 ERROR java.util.concurrent.ExecutionException: com.alibaba.dubbo.rpc ...
- com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote method解决方法
报错日记: Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote method: getUserAuthLeve ...
- bubbo调用Failed to invoke remote method异常解决
bubbo调用服务异常: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote method: getPlanFlowInfo, pr ...
- com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
查看了网友们的错误原因, 需要进行实例化的类没有进行实例化,具体没有实例化的类会在错误信息中显示,在错误信息中搜索“Serializable”即可找到将其实现序列化可消除错误. 是在使用Dubbo提供 ...
- git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation
在服务器添加完公钥后报错 sign_and_send_pubkey: signing failed: agent refused operation 解决方案: eval "$(ssh-ag ...
- git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation的解决办法
在服务器添加完公钥后报错 sign_and_send_pubkey: signing failed: agent refused operation 这个时候我们只要执行下 eval "$( ...
随机推荐
- iOS博客列表
国外 iOSDevWeekly NSHipster NSBlog objcio Raywenderlich Bignerdranch NSScreencast 需FQ Pilky.me jeremyw ...
- iphone/iOS 访问本地数据库sqlite3
Phone也支持访问本地数据库Sqlite 3.这里简单的介绍一下iPhone上Sqlite 3的使用方法. 首先需要在项目中引用Sqlite 3的开发包,下面是在iPhone SDK 3.0下的目录 ...
- wpa破解学习
TENDA 159031106A iPhone 192.168.0.11 90:27:E4:53:49:D6 18:58:52 PC-201211262044 192.168.0.12 00:F1: ...
- EasyMvc入门教程-高级控件说明(16)信息框控件
网页开发的时候,会经常向用户显示一些信息,比如执行结果,注意事项等,下面展示一种最简单的信息提示: 代码如下: @Html.Q().Msg().Text("初始化信息").Auto ...
- Flutter开发记录part1
(1)AppBar:automaticallyImplyLeading//是否带返回leading箭头 (2)非route路由页面跳转 :Navigator.of(context).push(Mate ...
- extern static const abstract virtual
extern static const abstract virtual const const.常量,初始化过后值不能再变化的变量.
- NYOJ92 图像实用区域 【BFS】
碰到了一个曾经从未见过的奇怪问题:先上截图: 执行号 用户 题目 结果 时间 内存 语言 提交时间 895360 userid=%E9%95%BF%E6%9C%A8" style=" ...
- Swift初窥----语法进阶
缺省绑定(Optional Binding 自己主动置空) 通过在类型变量后,加上?,能够实现缺省绑定为nil var window: UIWindow? 就是说,假设不正确window赋值,则win ...
- layui-简单辅助元素 - 页面元素
本篇主要集中罗列页面中的一些简单辅助元素,如:引用块.字段集区块.横线等等,这些元素都无需依赖任何模块 <!DOCTYPE html> <html> <head> ...
- C与C++在形參的一点小差别
先看一下以下的代码: int fun(a,b) int a; int b; { return 10; } void main(int argc, char ** argv) { fun(10); re ...