spring异常通知报错At least one handler method must be found in class [class aop.LogException]

2019/3/30

问题描述
在编写好异常通知和配置文件之后运行测试类,出现了错误:
in thread “main” java.lang.IllegalArgumentException: At least one handler method must be found in class [class aop.LogException]

解决思路
该报错已经将错误定位到了编写异常通知的类当中,发现在本类中找不到错误。于是进入本类的接口类ThrowsAdvice中进行核对发现源码中有一下描述:

 * <pre class="code">void afterThrowing([Method, args, target], ThrowableSubclass);</pre>
 * <p>Some examples of valid methods would be:
 * <pre class="code">public void afterThrowing(Exception ex)</pre>
 * <pre class="code">public void afterThrowing(RemoteException)</pre>
 * <pre class="code">public void afterThrowing(Method method, Object[] args, Object target, Exception ex)</pre>
 * <pre class="code">public void afterThrowing(Method method, Object[] args, Object target, ServletException ex)</pre>

该段代码表示:

  1. 在接口实现类中必须按照格式编写
    void afterThrowing([Method, args, target], ThrowableSubclass)
    (中括号表示里面的参数要不全都存在,不要全都不存在!)
    2.给了几个例子例如
    public void afterThrowing(Exception ex)
    可以发现,自己根据1中格式编写的方法必须时public。

解决方法

经过核对之后,发现自己写的接口实现类中的方法没有加 public 加以修饰,于是加上 public,解决了错误。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值