Spring WebSocket Connecting with SockJS to a different domain

前端 未结 4 1302
有刺的猬
有刺的猬 2021-02-02 09:30

WebSockets in Spring is a rather new topic that I;m tiring to find a bit more.

My problem is with connecting to a service from a different domain, I\'m working on with

4条回答
  •  梦毁少年i
    2021-02-02 09:39

    Jax's anwesr was correct :)

    The registerStompEndpoints method gives us the opportunity to set the Allowed Origins. We need to add it before the "withSockJs()" option.

        @Override
        public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
            stompEndpointRegistry.addEndpoint("/BO/socket").setAllowedOrigins("*").withSockJS();
        }
    

提交回复
热议问题