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、不能有重復的注入

