목차
문제발생
MessageSource 테스트중 getMessage() 호출시 한글이 ?? 되는 문제발견
더보기
resources/messages.properties
hello=안녕
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.MessageSource;
import static org.assertj.core.api.Assertions.*;
@SpringBootTest
public class MessageSourceTest {
@Autowired
MessageSource ms;
@Test
void helloMessage() {
String result = ms.getMessage("hello", null, null);
assertThat(result).isEqualTo("안녕");
}
}
문제원인
properties 파일은 기본 인코딩으로 ISO-8859-1로 설정되어 있는데 ISO-8859-1은 한글을 지원하지 않는다.
* ISO-8859-1은 서유럽 언어 지원
properties 인코딩 관련 클래스
PropertiesPropertySourceLoader.class
// PropertiesPropertySourceLoader에서 OriginTrackedPropertiesLoader 생성
OriginTrackedPropertiesLoader.class
// OriginTrackedPropertiesLoader의 내부 클래스이며 여기서 ISO_8859_1로 Set
CharacterReader.class
문제해결
1. 일단 해당 properties 파일을 복사하거나 백업하자. (인코딩 과정에서 한글이 깨질 수 있으므로)
2. 윈도우 기준 File -> Settings 클릭하여 Settings 창을 연다.
3. File Encodings에서 UTF-8로 바꾸고 Transparent native-to-ascii conversion 체크
참고사이트
https://kim-jong-hyun.tistory.com/57
https://velog.io/@ehdrms2034/Spring-Application.properties-%ED%95%9C%EA%B8%80%EA%B9%A8%EC%A7%90
댓글