[Error] JSP 파일을 못 읽을 때 (Error resolving template)
[Error] JSP 파일을 못 읽을 때 (Error resolving template)
문제상황
Spring Boot와 JSP, JSTL 기반의 웹 프로젝트를 구성하다가 Spring이 WEB-INF에 있는 JSP 파일을 불러오지 못함.
해결 과정
의존성 설정
Spring Boot에서는 기본적으로 JSP를 지원하지 않으므로 다음의 의존성을 추가해줘야 함.
1
2
3
4
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
implementation 'jakarta.servlet:jakarta.servlet-api'
implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api'
implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl'
application.properties 수정
WEB-INF 디렉토리를 사용하기 위해 prefix
와 suffix
를 작성해준다.
1
2
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
또한 JSP를 수정했을 때 서버를 재실행시키지 않아도 바로 반영되도록 development
를 활성화시킨다.
1
server.servlet.jsp.init-parameters.development=true
모든 설정과 JSP 파일을 작성한 뒤에 서버를 실행시키면 다음과 같이 잘 작동하는 것을 확인할 수 있다.
Reference
This post is licensed under CC BY 4.0 by the author.