Due to work needs, a platform-independent web project needs to be built to collect bugs and suggestions from other systems. Considering the expansion of cross-domain and later online communication, I decided to use webSocket. In addition, the system itself is based on Spring, so I built a very simple project according to Spring's official documents.
Built based on maven, it is very simple and fast. I won’t talk nonsense here, just go to the topic:
The entire project structure is so simple, so I won’t go into details. The source code of this project will be uploaded later. You can take a look. After the installation official instructions are completed, I found that no matter how I access it, it will be 404.
I have also checked countless resources and Baidu has countless questions in the past few days. I found that the solution did not focus on the key points.
However, someone in the middle mentioned the key point: the webSocket request is essentially an http request, so it must go through an interceptor, that is, it needs to be configured to intercept in the DispatchServlet. Then if it is cross-domain, you must set the connection domain name address when configuring the access address. For example, two key points will be pasted below:
This is the request address of the page:
So, after you configure this, you will find that there is no problem;
In fact, the official documentation also mentioned it, but I didn’t know exactly what I wanted to express at that time, such as:
appendix:
1. Official document: spring Chinese document
2. Project source code: download address
Then the story ends here and it will end.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.