org.springframework.beans.factory.UnsatisfiedDependencyException: 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 [D:\IDEA\hyper-cloud\hyper-cloud-demo\build\classes\main\com\hyper\mapper\UserMapper.class]: Unsatisfied dependency
没法注入Dao中的Bean!
解决分析后来经研究发现,SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! “Application类”是指SpringBoot项目入口类。这个类的位置很关键:
若是Application类所在的包为:io.github.gefangshuai.app
,则只会扫描io.github.gefangshuai.app
包及其全部子包,若是service或dao所在包不在io.github.gefangshuai.app
及其子包下,则不会被扫描!java
解决:@ComponentScan注解进行指定要扫描的包以及要扫描的类。git
参考:http://blog.csdn.net/u014695188/article/details/52263903github