完美解决SpringMVC对Ajax访问WebSocket接口的跨域问题(二)


客户端使用SockJS连接SpringMVC-WebSocket接口时,发现跨域问题。解决方案如下:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer
{
    public void registerStompEndpoints(StompEndpointRegistry registry)
    {
        registry.addEndpoint("/pushServer").setAllowedOrigins("*").withSockJS(); 
    }
}

你可能感兴趣的:(日常问题)