WebMvcTest μ€ NoSuchBeanDefinitionException μλ¬ ν΄κ²°
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hospitalController' defined in file [C:\Users\ikyoo\Desktop\λ©μμ΄μ¬μμ²λΌ λ°±μλ μ€μΏ¨\λ³μμΉμ¬μ΄νΈνλ‘μ νΈ\web\out\production\classes\hospital\web\controller\HospitalController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'hospital.web.service.HospitalService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:90)
... 72 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'hospital.web.service.HospitalService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 90 more
WebMvc ν μ€νΈ μ½λμμ μμ κ°μ μλ¬κ° κ³μν΄μ λ°μνλ€.
κ·Όλ°, μμνμ μ΄ λλ UserController λΌλ νμΌ ν μ€νΈλ₯Ό μ€νμ€μ΄μλλ°, μκΎΈ, hospital κ΄λ ¨ μμ€ μ½λμμ μλ¬λ₯Ό λ°μμν€λ μν©μ΄μλ€.
ν΄κ²°μ±
μ, @WebMvcTest(ν
μ€νΈνκΈ°λ₯Ό μνλ ν΄λμ€.class)
λ₯Ό λͺ
μν΄μ£Όμ΄μΌ μλ¬λ₯Ό λ°μμν€μ§ μλλ€.
@WebMvcTest(UserController.class)
μ΄μ²λΌ ν
μ€νΈ νκΈ°λ₯Ό μνλ ν΄λμ€λ₯Ό λͺ
μνλ μλ¬κ° λ°μνμ§ μκ² λμλ€.