spring整合mybatis启动tomcat报错:Exception encountered during context initialization - cancelling refresh a

本文详细解析了一个关于Spring框架中依赖注入失败的异常案例,通过检查配置文件、注解value及逐步排查,最终发现是在Service接口上缺少@Service注解导致的问题。此案例强调了正确使用注解和服务层配置的重要性。
摘要由CSDN通过智能技术生成

下面是完整异常:

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注解,没想到竟然成功了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值