SpringBoot项目UnsatisfiedDependencyException: Error creating bean with name
解决方法就是在mapper类上加@mapper或者在主类上加@Mapperscan("xxx")原因是没找到mapper,去mapper里面找才发现没加@mapper注解。发现其中关键字在datasource,才发现没加mysql依赖。其中xxx填上你的mapper包名,比第一个方法方便。刷新maven,运行成功。但加了注解后发现又报错。
学习springboot写项目时,运行测试项目发现报错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.coder.day07.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
原因是没找到mapper,去mapper里面找才发现没加@mapper注解
解决方法就是在mapper类上加@mapper或者在主类上加@Mapperscan("xxx")
其中xxx填上你的mapper包名,比第一个方法方便
但加了注解后发现又报错
Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [A:\javastudy\springboot_homework\day07\target\classes\com\coder\day07\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource
发现其中关键字在datasource,才发现没加mysql依赖
在pom文件中加入
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
刷新maven,运行成功
更多推荐



所有评论(0)