下面是完整异常:
org.springframework.context.support.AbstractApplicationContext 2020-05-08 11:51:48 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountService': Unsatisfied dependency expressed through field 'accountDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xx.dao.AccountDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
这个异常我在网上查找了一下,也按照步骤操作了但是没用
解决方法:
- 看配置文件是否正确
- 看是不是注解里面的value是否正确
- 然后我认真看了异常:Error creating bean with name ‘accountService’: Unsatisfied dependency expressed through field ‘accountDao’;我大概理解应该是给service里面注入dao失败;unsatisfied dependency (不满意的依赖).我以为是jar包的错误,就去重新导入mybatis-spring的包。后面还是没用
-最后我看是注入问题。就从controller层一步一步找;我的@Service注解标在了实现类上面;controller类里面是用autowired注解给service接口进行注入。然后我抱着试一试的心态给service接口也加了@Service注解,没想到竟然成功了。
本文详细解析了一个关于Spring框架中依赖注入失败的异常案例,通过检查配置文件、注解value及逐步排查,最终发现是在Service接口上缺少@Service注解导致的问题。此案例强调了正确使用注解和服务层配置的重要性。
1万+

被折叠的 条评论
为什么被折叠?



