英文:
ResponseEntityExceptionHandler error with new Spring Boot version
问题
虽然我之前在较早版本的Spring Boot中可以使用ResponseEntityExceptionHandler
,就像在这个链接中展示的那样,但是当我在我的新应用程序中实现相同的异常处理程序(Spring Boot版本3.0.2)时,对于handleExceptionInternal
方法,我会得到以下错误:
> 方法未覆盖其超类中的方法
所以,我可以通过不扩展ResponseEntityExceptionHandler
来解决这个问题,但我不确定是否有更好的方法来解决这个问题。
对于这个问题有任何想法吗?
英文:
Although I could use ResponseEntityExceptionHandler
with the previous Spring Boot versions as shown on this example, I get the following error for the handleExceptionInternal
method when I implement the same exception handler in my new app (Spring Boot version 3.0.2):
> Method does not override method from its superclass
So, I can fix the problem by not extending ResponseEntityExceptionHandler
, but I am not sure if there is a better way to fix this problem.
Any idea for this problem?
答案1
得分: 1
方法的签名不同,所以现在你得到了这个错误。检查签名这里。
基本上你需要改变的是:HttpStatus
--> HttpStatusCode
。
以下是覆盖该方法的示例:
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex,
Object body,
HttpHeaders headers,
HttpStatusCode statusCode,
WebRequest request){
// 在这里添加你的代码....
}
英文:
The signature of the method is different so now you get that error. Check signature here.
Basically what you need to change is: HttpStatus
--> HttpStatusCode
Here is an example of overriding this method:
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex,
Object body,
HttpHeaders headers,
HttpStatusCode statusCode,
WebRequest request){
//your code here....
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论