두 손끝의 창조자

No ServletContext set - @WebAppConfiguration 본문

Spring

No ServletContext set - @WebAppConfiguration

codinglog 2020. 6. 12. 14:14

테스트 돌리는데 예외 발생

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set

Caused by: java.lang.IllegalStateException: No ServletContext set

해결방법

테스트 클래스에 @WebAppConfiguration 추가

@WebAppConfiguration?

@WebAppConfiguration은 통합 테스트를 위해 로드된 ApplicationContext가 WebApplicationContext 여야 함을 선언하는 데 사용하는 클래스 레벨 어노테이션입니다.

테스트 클래스에 @WebAppConfiguration이 있으면 웹 애플리케이션의 루트 경로에 대한 기본값을 사용하여 테스트를 위해 WebApplicationContext를 로드해야 함을 나타냅니다. 기본값을 무시하려면 value () 속성을 통해 명시적 리소스 경로를 지정하십시오.

@WebAppConfiguration은 단일 테스트 클래스 또는 테스트 클래스 계층 내에서 @ContextConfiguration과 함께 사용해야 합니다.

이 주석은 메타 주석으로 사용되어 사용자 정의 작성된 주석을 작성할 수 있습니다.

반응형
Comments