vue集成websocket,打开连接时,403(Forbidden)
如下:websocket和socket
后台是spring cloud,解决办法:
package com.fig;
import t.annotation.Configuration;
import fig.MessageBrokerRegistry;
import org.springframework.fig.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.fig.annotation.EnableWebSocketMessageBroker;
import org.springframework.fig.annotation.StompEndpointRegistry;
import org.springframework.fig.annotation.WebSocketMessageBrokerConfigurer;
/**
*
*/
@Configuration
@EnableWebSocketMessageBroker
//通过EnableWebSocketMessageBroker 开启使⽤STOMP协议来传输基于代理(message broker)的消息,此时浏览器⽀持使⽤@MessageMapping 就像⽀持@RequestMapping⼀样。public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) { //endPoint 注册协议节点,并映射指定的URl
//注册⼀个Stomp 协议的endpoint,并指定 SockJS协议
registry.addEndpoint("/endpointWisely").setAllowedOrigins("*").withSockJS();
/
/注册⼀个名字为"endpointChat" 的endpoint,并指定 SockJS协议。点对点-⽤
registry.addEndpoint("/endpointChat").setAllowedOrigins("*").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {//配置消息代理(message broker)
//⼴播式应配置⼀个/topic 消息代理
//点对点式增加⼀个/queue 消息代理
}
}
注册endpoint 时加上 .setAllowedOrigins("*")
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论