org.springframework.beans.factory.BeanCreationException
程序员文章站
2022-04-14 20:42:04
...
项目启动过程中报如下错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.daojia.jz.withdraw.dao.IDrawLogDao com.daojia.jz.withdraw.service.impl.ApplyDrawServiceImpl.iDrawLogDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.daojia.jz.withdraw.dao.IDrawLogDao] 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 46 more
看到这个错误乍一看是很懵的,不知道如何下手,看下日志提示找到不到对应的bean,bean注入失败。根据日志提示找到对应文件,思考为什么会注入失败,不能用
@ autowired的,根据日志找到对应的文件,发现类名上竟然忘记加@Service注解,总结下报这个问题的场景:
注入失败的原因主要有:
1.没有添加注解。例如:@Service @Autowared @Controller
2.错误的注入方法
3.对于web.xml中监听器的xml配置错误。 所以我们要解决此问题,主要检查注解正确的添加,包引入是否正确,以及检查web.xml监听器的配置。
注:上面是我遇到的情景,可能不够全面,仅供参考希望对大家有所帮助。
上一篇: CAT应用启动报错:java.net.UnknownHostException: org.cat
下一篇: web服务启动异常(org.springframework.asm.ClassReader.(Unknown Source))
推荐阅读
-
springMVC常见错误-解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.spring
-
org.springframework.beans.factory.BeanCreationException
-
出现org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userContro
-
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field
-
springMVC常见错误-解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.spring