
log4j2 + LoggingFilter 로 로그 작업 중 한글 깨짐이 발생했다.

response 인코딩을 보니 UTF-8로 별도 지정이 안되어있어서 기본값인 ISO-8859-1로 설정되어 있다.
@PostMapping("/login")
public ResponseEntity<?> login(@RequestBody LoginRequest request) {
LoginResponse loginResponse = authService.login(request);
return ResponseEntity
.status(HttpStatus.OK)
.contentType(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8)) // 이부분
.body(loginResponse);
}
`.contentType(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8))` 이렇게 응답에 UTF-8로 응답해서 내보내는 방법이 있는데, 너무 비효율적이다.
String body = new String(response.getContentAsByteArray(), StandardCharsets.UTF_8);
사용하는 부분에서 강제적오르 UTF-8을 사용하도록 설정했다.

한글이 정상적으로 나오는 걸 확인했다.
'오류' 카테고리의 다른 글
| [SpringBoot] Entity 객체 반환 오류 (SerializationFeature.FAIL_ON_EMPTY_BEANS) (2) | 2025.07.08 |
|---|---|
| [SpringBoot] No appenders present in context [default] for logger [org.jboss.logging]. (0) | 2025.07.04 |