비전공자 공부일기/::::: 묻고 답찾기
[디버그] Spring jUnit 스프링 제이유닛 테스트에서 java.lang.IllegalStateException: Failed to load ApplicationContext
와니_
2020. 9. 10. 21:01
스프링으로 프로젝트를 하면서 항상 같은 에러 문구들을 보는 것 같으면서
원인은 또 그때그때 다르고.. 오만가지 에러를 다 경험해보는 것 같다.
오늘의 에러 디버깅 기록
에러메시지가 아래와 같이 뜰 때...
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: WebApplicationObjectSupport instance [ResourceHttpRequestHandler [locations=[class path resource [resources/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@46731692]]] does not run in a WebApplicationContext but in: org.springframework.context.support.GenericApplicationContext@61df66b6: startup date [Thu Sep 10 20:39:14 KST 2020]; root of context hierarchy
Caused by: java.lang.IllegalStateException: WebApplicationObjectSupport instance [ResourceHttpRequestHandler [locations=[class path resource [resources/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@46731692]]] does not run in a WebApplicationContext but in: org.springframework.context.support.GenericApplicationContext@61df66b6: startup date [Thu Sep 10 20:39:14 KST 2020]; root of context hierarchy
java.lang.IllegalStateException: Failed to load ApplicationContext 라는 문구가 떠서
뭔가 객체생성을 위한 클래스 어노테이션이 빠졌을거란 생각은 했는데
그게 설마 테스트 클래스에서 난 에러일 줄은 몰랐다.
테스트를 위한 junit 클래스의 위에 @WebAppConfiguration 한줄 추가해줬더니 간단히 해결
참고로 현재 내 제이유닛 클래스에는 아래와 같이 어노테이션들이 붙어있음
