
正文
SpringBoot:Service层使用@Autowired 注解 mapper对象爆红问题
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
问题点
- 这个报错可能导致程序运行大面积爆红
- 这个报错会逼疯强迫症
解决方法
为避免程序运行报错 ,需要在Application.class添加注解@MapperScan(mapper包位置)
@SpringBootApplication
// 扫描包mapper注解
@MapperScan("com.linghangcloud.fegert.mapper")
public class FegertApplication { public static void main(String[] args) {
SpringApplication.run(FegertApplication.class, args);
}
}
修改避免了运行时异常,但是问题依旧。
每个mapper类前加上@Repository注解
@Repository
@Mapper//@Mapper注解 springbboot能否自动扫描识别
public interface UserMapper extends BaseMapper<User>{
}
文章转载至:https://blog.csdn.net/weixin_44779019/article/details/101112387






