java - The websocket server's onMessage() method reports a null pointer exception as soon as it operates the database.
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-17 09:16:37
0
2
1107

I want to use websocket to implement the new message reminder function. For example, a posts an article and someone replies to a. When a goes online, a message reminder will appear, as shown below

If you directly use session.getBasicRemote().sendText("haha"); in the onMessage() method in the background, it can run normally, but a null pointer exception occurs when operating the database..


Front-end js processing:

Has anyone encountered the same problem? Please let me know..

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
仅有的幸福

This null pointer has nothing to do with weosocket. It should be a problem with the dependency injection of your messageService instance.
You should check whether your MessageService is hosted by an IOC container, that is, whether the class is annotated with @Service or @Component.

黄舟

During the development process, a class that is not managed by spring (such as MessageController) wants to call a method of an object that is managed by spring (such as MessageService object). If we call the method like the following code, a null pointer will appear. abnormal.

Solution:

Use ApplicationHelper to get the required MessageService object

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!