可以不受拦截器影响
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
// config.addAllowedOriginPattern("*");
// config.setAllowCredentials(true);
config.addAllowedMethod("*");
config.addAllowedHeader("*");
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
注解配置,拦截器可能有影响其不生效
@CrossOrigin
class XXX{}
websocket配置 ws 对应 http,wss对应https,严格对应,不对应报错!
ws = new WebSocket("ws://ip:port/notify/token");
ws.onopen = function()
{
// Web Socket 已连接上,使用 send() 方法发送数据
ws.send("发送数据");
alert("数据发送中...");
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
alert("数据已接收...");
console.log(received_msg);
};
ws.onclose = function()
{
// 关闭 websocket
alert("连接已关闭...");
};
{
// 关闭 websocket
alert("连接已关闭...");
}
|