侧边栏壁纸
博主头像
宁静致远博主等级

行动起来,活在当下

  • 累计撰写 14 篇文章
  • 累计创建 11 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Springboot自定义类@Resource注入为null的问题

Administrator
2024-03-26 / 0 评论 / 0 点赞 / 2 阅读 / 937 字

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

0

评论区