How should the front end be called after SpringBoot has written the back-end WebSocket code? (not on the same project)

< H1 > the backend uses SpringBoot integrated WebSocket services < / H1 >

the Java code is as follows:

< H2 > configure WebSocket < / H2 >
// 
var ctx = ""
//  Scoket 
var socket = new SockJS(`${ctx}/endpointSang`)
var stompClient = Stomp.over(socket)
// 
stompClient.connect({}, frame => {
  console.log(":", frame)
  stompClient.subscribe(`${ctx}/topic/getResponse`, response => {
    console.log(":", JSON.parse(response.body).responseMessage)
  })
})
// 
stompClient.send(`${ctx}/welcome`, {}, JSON.stringify({ name: "rx" }))

so, what happened? What should we do?

Apr.28,2021
As stated in the

exception, you should use the address of http to link, but since it is sockjs, you cannot use ws and wss addresses.


it is speculated that the configuration of java is not well done. Since java has forgotten all, Refer to https://blog.csdn.net/wobuaiz.
https://blog.csdn.net/Mars_we.. It is said in this article that you should use the full name of the address when importing socketjs. And the connection uses http instead of websocket's ws


recently wrote a similar custom configuration interceptor and broadcast message prefix

clipboard.png

then the business layer uses message templates, others as usual

@Autowired
private SimpMessagingTemplate messagingTemplate;


messagingTemplate.convertAndSend("/topic/notice", string);

Menu