无法从 static 上下文引用非 static 字段

错误:无法从 static 上下文引用非 static 字段 ‘tagLocatorMapper’
《无法从 static 上下文引用非 static 字段》
解决方式

@Component
public class StaticTagLocatorMapper { 
    @Autowired
    private TagLocatorMapper tagLocatorMapper;
 
    public static TagLocatorMapper staticTagLocatorMapper;
    // 项目启动时把TagLocatorMapper 交给静态的staticTagLocatorMapper
    @PostConstruct
    public void init() { 
        staticTagLocatorMapper = this.tagLocatorMapper;
    }
}

使用

StaticTagLocatorMapper.staticTagLocatorMapper.insertTagLocator()

《无法从 static 上下文引用非 static 字段》

    原文作者:浮_雲
    原文地址: https://blog.csdn.net/qq_31275085/article/details/111170608
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞