|
|
@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
|
|
+import org.springframework.web.servlet.resource.NoResourceFoundException;
|
|
|
+
|
|
|
import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -54,6 +56,16 @@ public class GlobalExceptionHandler {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 静态资源未找到(如 /favicon.ico),直接返回404,不打印 ERROR 日志。
|
|
|
+ */
|
|
|
+ @ExceptionHandler(NoResourceFoundException.class)
|
|
|
+ public ResponseEntity<Map<String, String>> handleNoResource(NoResourceFoundException ex) {
|
|
|
+ log.debug("静态资源未找到: {}", ex.getMessage());
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
|
+ .body(Map.of("error", "not found"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 兜底:所有未预期异常。
|
|
|
* 对应 Go: respondError(c, http.StatusBadGateway, err)
|
|
|
*/
|