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语句 通过spring的上下文来获取吧 Mapper加@Mapper注解了嘛?
页:
[1]