org.springframework.web.context.support.XmlWebApplicationContext

2022. 10. 3. 21:15JAVA & SPRING/에러

반응형

에러 코드

게시판 프로젝트를 만들기 위해 자바 기본 설정을 다 끝냈고, 게시판 리스트를 출력하기 위해 Mapper, Service, Controller, jsp까지 다 작성했다.

근데 서버를 돌리자 마자 에러가 발생했다.

WARN : org.springframework.web.context.support.XmlWebApplicationContext

 

 
WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'boardController' defined in file [/Users/---/Spring/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/BoardBook1/WEB-INF/classes/com/board/controller/BoardController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.board.service.BoardService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed

 

에러 해결

코드를 다시 살펴보니 root-context.xml에 component-scan을 작성해주지 않아서 에러가 발생했다.

 

  • component-scan 이란

@Controller, @Service, @Repository, @Component 어노테이션이 붙여진 클래스들인 빈에 등록된 준비가 된 것으로 간주된다.

component-scan은 root-context.xml에 <context:component-scan base-package="패키지 이름"/> 를 작성함으로 빈에 등록해주는 것이다.

 

root-context에 컴포넌트 스캔으로 서비스 패키지를 빈으로 등록해주니 정상 작동한다!

 


root-context.xml에 component-scan 작성했는지 확인하자!

반응형