在一个项目中@MapperScan和@Mapper共存问题
测试案例
目录结构

service类中注入所有Mapper接口;

- 仅在Mapper接口上使用@Mapper注解,程序正常启动;
- 仅在启动类上使用@MapperScan({“com.example.mappertest.mapper”})注解,且mapper接口位于mapper文件夹下,项目成功启动;
- Mapper接口位于mapper文件夹下,使用@Mapper注解,并且启动类上使用@MapperScan({“com.example.mappertest.mapper”})注解,项目成功启动;
- Mapper接口移动到mapper1文件夹下,使用@Mapper注解,并且启动类上使用@MapperScan({“com.example.mappertest.mapper”})注解,项目无法启动;
- UserMapper接口移动到mapper1文件夹下,使用@Mapper注解,并且启动类上使用@MapperScan({“com.example.mappertest.mapper”})注解,项目无法启动;
报错:Consider defining a bean of type 'com.example.mappertest.mapper1.UserMapper' in your configuration.
结论
@MapperScan和@Mapper同时存在时,@MapperScan 注解优先级高,@Maper 注解失效。