Failed to load ApplicationContext
今天遇到一个意料之外的错误,搜索半天发现都是很老的信息一无所获,最后自己仔细读取报错信息才发现的错误
Caused by: 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.bing.blog.mapper.UserMapper‘ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
因为之前使用mybatis-plus的代码自动生成器,在项目结构中有生成了 pojo包和mapper包,并且注解都配置好了,我猜想可能是因为spring容器中默认是单例模式,导致识别错误或者什么其他的错误
果然在删除多余的包后问题解决~
总结:
? springBoot也是约定大于配置,
@MapperScan("com.bing.mapper")
,不能有多余的包
1、包的目录结构要固定
2、不能有多余的包
3、不能有重复的注入