TIssue | IllegalStateException: Faild to load ApplicationContext
IllegalStateException에 대한 글이다.
상황
새로운 ServiceImple을 만든 뒤 테스트를 실행 중 IllegalStateException: Faild to load ApplicationContext... 이 발생했다.
오류내용
IllegalStateException: Faild to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL
...
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file ...
[.../target/classes/mapper/boardMapper.xml]';
...
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
...
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.....dao.BoardMapper.updateCommentCnt. please check file [.../target/classes/mapper/boardMapper.xml] and file [.../target/classes/mapper/boardMapper.xml]
오류 파악 시도
- 1. @WebAppConfiguration
Test 객체에 WebAppConfiguration 애너테이션을 추가하면 된다고 많은 글들이 말하지만 이경우는 그렇지 않았다.
- 2. root-context.xml
root-context.xml 파일에서 sqlSessionFactory 빈의 property인 mapperLocations를 살펴보았다. 하지만 문제가 없었다.
- 3. BoardMapper.updateCommentCnt. please check file
오류 내용에서 빨간색으로 표시된 부분이 있다. 여기서 같은 파일을 확인해 보라고 한다. 원인은 여기에 있었다.
원인 및 해결방법
Mapper.xml 파일에서 중복 sql이 작성돼 있었다. 하여 중복으로 작성한 sql문 하나를 삭제해 주었다.
결과
문제없이 정상작동 됐다.