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

 

posted @ 2020-11-06 11:30  怒吼的萝卜  阅读(3271)  评论(0编辑  收藏  举报