美文网首页
解决工具类中使用注入的service为null

解决工具类中使用注入的service为null

作者: 黎先生_ | 来源:发表于2023-08-18 10:14 被阅读0次
@Component
public class ChatUtil {
     // 这里使用静态,让 service 属于类
    private static ChatService chatService;

    // 注入的时候,给类的 service 注入
   @Autowired
   public void setChatService(ChatService chatService) {
         ChatUtil .chatService = chatService;
   }
}

相关文章

网友评论

      本文标题:解决工具类中使用注入的service为null

      本文链接:https://www.haomeiwen.com/subject/jlfdmdtx.html