Springboot自定义类@Resource注入为null的问题
解决方法就是使用PostConstruct注解,代码如下
@Component
public class SyncExtend implements FormExtend {
// 静态的实例
private static SyncExtend syncExtend;
// 需要被注入的Dao
@Resource
private SyncDao syncDao;
// 空参构造
public SyncExtend() {
}
@PostConstruct
public void init() {
syncExtend = this;
}
}
// 使用方法
syncExtend.syncDao.xxxx
评论区