报错内容是这样的:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.jiuyun.miaosha.MiaoshaApplicationTests': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jiuyun.miaosha.dao.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
在找了许久之后 终于找到了报错的原因:
原来是我没有加依赖
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency>
加上这个依赖包就可以了
总结 :
这只是报错的一种 还有很多种 我给大家一 一列出来
1:在controller的service的时候使用了注解@Autowired。但是在service的实现类中未使用@Service注解,导致找不到
2:接口没有写实现类,实现类实现错了接口
3:有可能没有找到需要扫描的包(也就是xml文件出现了错误,如果xml文件没有错误,就去调用xml文件的web-info目录下)
4:注入是否正确
5:包是否完整