문제 세부 정보(RFC 7807)
표준화된 오류 응답을 반환해 보세요.
문제 세부 정보(RFC 7807)은(는) CoddyKit의 무료 Spring Boot 4 Microservices & REST APIs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Spring Boot 4 Microservices & REST APIs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Spring Boot 4 Microservices & REST APIs 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
A Standard for API Errors
Every team inventing its own error JSON leads to chaos for API consumers. RFC 7807 defines Problem Details — a standard, machine-readable error format with a media type of application/problem+json.
The Problem Details Fields
The standard defines a small set of fields:
type— a URI identifying the problem kindtitle— short, human-readable summarystatus— the HTTP status codedetail— specifics for this occurrenceinstance— URI of the specific occurrence
Spring’s ProblemDetail
Spring Framework 6 / Boot 3 ship a built-in ProblemDetail class that models RFC 7807 directly. You construct it with a status and customize the standard fields.
ProblemDetail pd = ProblemDetail.forStatusAndDetail(
HttpStatus.NOT_FOUND, "Order 42 was not found");
pd.setTitle("Order Not Found");
pd.setType(URI.create("https://errors.example.com/order-not-found"));Returning ProblemDetail
Return a ProblemDetail from a controller or exception handler. Spring serializes it as application/problem+json with the right status.
@ExceptionHandler(OrderNotFoundException.class)
public ProblemDetail handle(OrderNotFoundException ex) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(
HttpStatus.NOT_FOUND, ex.getMessage());
pd.setTitle("Order Not Found");
return pd;
}Enabling Built-in Problem Details
Spring Boot can convert its own framework exceptions into Problem Details automatically when you enable the property, giving consistent errors even for built-in failures.
spring:
mvc:
problemdetails:
enabled: trueExtending with Custom Properties
RFC 7807 permits extension members. Add domain-specific data — an error code, a correlation id, or field errors — via setProperty.
pd.setProperty("errorCode", "ORDER_NOT_FOUND");
pd.setProperty("correlationId", correlationId);
pd.setProperty("timestamp", Instant.now());ResponseEntityExceptionHandler
Extend ResponseEntityExceptionHandler in your @ControllerAdvice to inherit handlers for Spring’s standard exceptions, then override the hooks to shape them as Problem Details.
@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
// override protected handle... methods to customize
}Problem Details for Validation
Override the validation hook to express field errors as a Problem Details body with an extension array, giving clients structured, standard validation feedback.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex, HttpHeaders h,
HttpStatusCode status, WebRequest req) {
ProblemDetail pd = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST);
pd.setTitle("Validation Failed");
pd.setProperty("errors", ex.getBindingResult().getFieldErrors().stream()
.map(e -> Map.of("field", e.getField(), "message", e.getDefaultMessage()))
.toList());
return ResponseEntity.badRequest().body(pd);
}Why the type URI Matters
The type URI gives each problem a stable identity clients can branch on — more robust than parsing human text. Point it at documentation describing the error and how to recover.
Content Negotiation
Problem Details responses carry the application/problem+json content type. Clients can detect this media type to distinguish structured errors from normal success payloads.
HTTP/1.1 404 Not Found
Content-Type: application/problem+json
{ "type": "...", "title": "Order Not Found", "status": 404, "detail": "..." }Adopting the Standard
Using Problem Details makes your API errors predictable and interoperable:
- One shape across all endpoints and frameworks
- Machine-readable
typefor client logic - Extensible for domain-specific detail
Quick Check
Test your understanding of RFC 7807.
Recap
Problem Details standardize API errors.
- RFC 7807 defines
type,title,status,detail,instance - Spring’s
ProblemDetailmodels it; served asapplication/problem+json - Enable built-in conversion via
spring.mvc.problemdetails.enabled - Add extension members with
setProperty - Extend
ResponseEntityExceptionHandlerto shape framework errors
AI 튜터와 함께 Java을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 24
- 레슨
- 93
자주 묻는 질문
“문제 세부 정보(RFC 7807)” 강의는 무료인가요?
네 — “문제 세부 정보(RFC 7807)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Spring Boot 4 Microservices & REST APIs 강의 전체를 잠금 해제할 수 있습니다. Spring Boot 4 Microservices & REST APIs 강의에는 총 4개의 강의가 포함되어 있습니다.
“문제 세부 정보(RFC 7807)”에서 뭘 배우나요?
표준화된 오류 응답을 반환해 보세요. 브라우저에서 직접 실행하는 실습 코드로 Spring Boot 4 Microservices & REST APIs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Spring Boot 4 Microservices & REST APIs을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Spring Boot 4 Microservices & REST APIs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“문제 세부 정보(RFC 7807)” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Spring Boot 4 Microservices & REST APIs 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Spring Boot 4 Microservices & REST APIs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- @Valid로 빈 검증하기
- 사용자 지정 검증기
- @ControllerAdvice와 @ExceptionHandler
- 문제 세부 정보(RFC 7807)