-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
root-context.xml에 context:component-scan을 넣을시 에러가 발생합니다.
22.12.07 01:08 작성 조회수 244
0
root-context.xml에<context:component-scan base-package="kr.bit.model" />을 넣을시 ERROR: org.springframework.web.context.ContextLoader - Context initialization failed java.lang.ArrayIndexOutOfBoundsException: 40292가 발생하여 구글에서 검색해본결과 servlet-context.xml 에<context:component-scan base-package="kr.narp.myapp, kr.bit.model" />식으로 정의하여 해결했습니다. context:component-scan 을 여러개 할시 에러가 발생하는듯한데 이게 원인일까요?
답변을 작성해보세요.
1

박매일
지식공유자22.12.08 11:56
context:component-scan은 여러 개를 해도 상관은 없습니다.
servlet-context.xml에서 scan된 객체는 root-context.xml에서 정의된 객체를 사용할 수가 있는데
반대로 root-context.xml에서 scan된 객체는 servlet-context.xml에서 정의된 객체를 사용할 수가 없습니다. 그래서 database객체는 root-context.xml에서 scan하고
controller나 service는 servlet-context.xml에 생성하는 것이 바람직합니다.
답변 1