[스프링] 메시지 에러

hgh1472·2024년 2월 1일

스프링

목록 보기
3/8

인프런의 스프링 MVC 2편 - 백엔드 웹 개발 활용 기술 강의를 듣던 중 오류가 발생했다.

messages.properties를 통해 메시지 설정을 테스트하는 동작이었다.

@Test
void helloMessage() {
	String result = ms.getMessage("hello", null, null);
    assertThat(result).isEqualTo("안녕");
}

Cause: cannot assign instance of java.util.Collections$EmptyList to field java.lang.StackTraceElement.moduleVersion of type java.lang.String in instance of java.lang.StackTraceElement

모든 코드 내용도 정확하게 작성했다고 생각했는데 왜 오류가 나는지 이유를 찾다가 원인을 찾았다.

이유는 인코딩이었다.
messages.properties에 다음과 같이 작성되어 있다.

hello=안녕
hello.name=안녕 {0}

위의 내용을 보면 한글로 되어있어서 UTF-8로 인코딩 되어야 한다. 하지만 내 프로젝트의 설정에는 ISO-8859-1로 되어있어서 오류가 발생했던 것이다.
Setting/Preferences의 Editor/File Encodings로 가서 Default encoding for properties files를 UTF-8로 바꿔준다.

0개의 댓글