【发布时间】:2019-06-06 01:18:59
【问题描述】:
我正在为我的项目中创建的 Null 指针异常或任何其他未经检查的异常寻找 Spring 警报邮件系统,以便我可以在应用程序中出现问题的警报。目前我正在使用弹簧靴。我还希望通过邮件发送 Request Json,这样我就可以分析 Request JSON 是否有一些可能导致错误的数据。
最初我在考虑使用@RestControllerAdvice for @ExceptionHandler(value = Exception.class) 和调用JavaMailSender.send() 的实例,但问题是该方法(比如handleOtherException(Exception ex))将只接受Exception ex 作为参数并且我还希望将传入的请求添加到邮件。
我尝试添加如下所示的一个参数:
protected ResponseEntity<Object> handleOtherException(Exception ex,@RequestBody Student s1)
但我得到以下错误:
java.lang.IllegalStateException: Could not resolve method parameter at index 1 in protected org.springframework.http.ResponseEntity<java.lang.Object> com.example.demo.GlobalExceptionHandler.handleOtherException(java.lang.Exception,com.example.demo.Student) throws com.fasterxml.jackson.core.JsonProcessingException: No suitable resolver for argument 1 of type 'com.example.demo.Student'
我也尝试在 github 中查找,但找不到任何这样的东西。请提出解决此问题的任何代码或方法。
【问题讨论】:
标签: spring spring-boot email exception