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

2023-08-18  本文已影响0人  黎先生_
@Component
public class ChatUtil {
     // 这里使用静态,让 service 属于类
    private static ChatService chatService;

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

猜你喜欢

热点阅读