在Spring Boot项目的普通类(使用@Component注解),需要依赖注入mapper或service接口时,出现空指针异常的解决方法
- 该类使用@Component注解
- 添加一个本类类型的静态字段
- 创建一个初始化方法,贴上@PostConstruct 标签,用于注入bean
- 依赖注入mapper或service接口
- 最后直接在普通类中调用即可
// 该类使用@Component注解 |
在Spring Boot项目的普通类(使用@Component注解),需要依赖注入mapper或service接口时,出现空指针异常的解决方法
// 该类使用@Component注解 |