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..
仅有的幸福2017-06-17 09:18:37
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.
黄舟2017-06-17 09:18:37
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