Springboot自定义类中加入@Resource或@Autowired出现java.lang.NullPointerException解决方案:
@Component //不能省略
public class Student {
@Resource
private StudentService studentService;
private static Student serverHandler;
@PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
public void init() {
serverHandler = this;
serverHandler.studentService= this.studentService;
// 初使化时将已静态化的testService实例化
}
public void RegeditEvent() {
serverHandler.studentService.selectList();//调用Service方法
}
}