Troubleshooting
[SpringBoot] java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest
ondala
2025. 2. 18. 00:10
환경
STS 3.2.5
jakarta.servlet-api 4.0.4
Apache Tomcat 9.x
JDK 17
jakarta.servlet-api 5.0 이상 버전은 Tomcat 10.x 이상부터 가능합니다.
문제
- build.gradle 에 jakarta.servlet-api 4.0.4 추가했는데 main.jsp화면 호출 시 에러가 발생.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest] with root cause
java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest
원인
- SpringBoot 3.x 버전부터는 JDK도 17이상, JSP도 javax 가 아닌 jakarta 지원한다.
- 서블릿 패키지를 javax를 사용해서 오류 발생했음.
[ MainController.java ]
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
해결
- 서블릿 패키지를 jakarta 를 사용해서 오류 해결
[ MainController.java ]
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;