anlan668 发表于 2024-4-26 16:20

autowired注入为null

@Component
@ServerEndpoint(value = "/chat")
public class ChatEndpoint {
    @Autowired
    private AuctionMapper auctionMapper;


    private static Set<Session> clients = Collections.synchronizedSet(new HashSet<>());



    @OnOpen
    public void onOpen(Session session) {
      clients.add(session);
    }
    @OnClose
    public void onClose(Session session) {
      clients.remove(session);
    }



    @OnMessage
    public void onMessage(String message, Session session) throws IOException, SQLException {
      System.out.println("我是mess"+message);
      JSONObject json = new JSONObject(message);
      String text = json.getString("text");
      String senderId = String.valueOf(json.getInt("senderId"));
      String receiverId = String.valueOf(json.getInt("receiverId"));
      Message mg = new Message();
      mg.setSenderId(senderId);
      mg.setReceiverId(receiverId);
      mg.setJsonMsg(text);

      auctionMapper.InIoMessage(mg);注入为null运行不了SQL语句

dbisee 发表于 2024-4-26 18:12

通过spring的上下文来获取吧

jituidadada 发表于 2024-4-26 21:07

Mapper加@Mapper注解了嘛?
页: [1]
查看完整版本: autowired注入为null