package com.mahadi.InventoryManagementSystem.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import com.mahadi.InventoryManagementSystem.dto.Response;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<Response> handleAllExceptions(Exception exception) {
Response response = Response.builder()
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) // or other status code
.message(exception.getMessage()) // exception message
.build();
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
现在看屏幕截图。
在这里,构建器方法没有响应,但是我在响应类中添加了@builder注释。我未能修复它。我需要你的建议。我正在使用JDK 17与Spring Boot 3.0.0
如果您有一个自定义构造函数,则Lombok可能不会生成构建器方法,除非您在构造函数上指定@builder。
尝试重建项目:进行更改后,清洁和重建项目以确保正确处理Lombok的注释。