org.springframework.beans.factory.BeanCreationException: Injection of autowired dependencies failed

스프링으로 개발을 하다보면 다음과 같은 에러가 발생하는 경우가 있다.


로그를 대충 보면 의존성이 정상적으로 주입되지 않았음을 뱉어낸다.


원인은 Controller, Dao, Service 등에 어노테이션(annoation)을 정확하게 기재해주지 않아 발생하는 에러다.


필자의 경우엔 더 사소한 ServiceImpl에서 인터페이스를 implements를 해주지 않아 서비스가 주입되지 않아 발생한 에러 였다.


아래 내용들을 확인해보면 해결할 수 있다.


1. @Autowired, @Service, @Controller 등의 어노테이션을 잘 기재해줬는지


2. 오타가 없는지, 패키지 import가 재대로 되어있는지



org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.spring.webprojectegov.service.VideoService com.spring.webprojectegov.controller.annotation.VideoController.videoService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.spring.webprojectegov.service.VideoService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)

at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5409)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5707)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1702)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1692)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)




+ Recent posts