@MapperScan
@MapperScan:要扫描mapper类包的路径
还可以扫描多个包,如:
@MapperScan({"com.kfit.demo","com.kfit.user"})
如果mapper类没有在Spring Boot主程序可以扫描的包或者子包下面,可以使用如下方式进行配置:
@MapperScan({"com.kfit.*.mapper","org.kfit.*.mapper"})
@ComponentScan
ComponentScan做的事情就是告诉Spring从哪里找到bean(加注解的类@Controller,@Repository,@Service或@Component)
@Controller,@Repository,@Service或@Component)- 如果你的其他包都在使用了
@SpringBootApplication注解的mainapp所在的包及其下级包,则你什么都不用做,SpringBoot会自动帮你把其他包都扫描了 - 如果你有一些
bean所在的包,不在mainapp的包及其下级包,那么你需要手动加上@ComponentScan注解并指定那个bean所在的包