WebServlet 애노테이션 미인식

@WebServlet 애노테이션이 인식되지 않았다

@WebServlet(name = "frontControllerServlet", urlPatterns = "/*")
public class FrontControllerServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("FrontController.service");
    }
}

간단한 테스트 서블릿이었는데, 전혀 인식을 하지 못하는 것 같이, service 메서드 자체가 호출되지 않았다.

@ServletComponentScan 부착

@ServletComponentScan를 부착하지 않아서 생긴 문제였다. 스프링부트의 애플리케이션 클래스에 부착해주어야, 서블릿을 자동으로 스캔한다.

@ServletComponentScan
@SpringBootApplication
public class WebLibraryApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebLibraryApplication.class, args);
    }

}

댓글

개발자  김철준

백엔드 개발자 김철준의 블로그입니다.

주요 프로젝트