java - 'Access-Control-Allow-Origin' 标头包含多个值 ', *',但在 spring boot stomp 配置中只允许一个值
问题描述
我在 spring boot 中配置了 stomp,我设置了 setAllowedOrigins 但是当通过 chrome 连接到 Sockjs 时出现错误,我该如何解决这个问题?
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry
.addEndpoint("/agent")
.setAllowedOrigins(Arrays.stream(domainAllowed.split(",")).toArray(String[]::new))
//.setAllowedOrigins("*")
.withSockJS();
logger.info("out register");
}
@Bean
public CorsConfigurationSource corsConfigurationSource() {
logger.info("thong tin domain allowed: "+ domainAllowed);
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.stream(domainAllowed.split(",")).map(String::trim).collect(Collectors.toList()));
configuration.setAllowCredentials(true);
configuration.setMaxAge(-1L);
configuration.setAllowedMethods(Arrays.asList("*"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
CORS 策略已阻止从源“https://cli.ovp.vn/agent/info?t=1632386394912”访问 XMLHttpRequest:“Access-Control-Allow-Origin”标头包含多个值“https” ://domain.work, *',但只允许一个。
stomp.min.js:8 哎呀!失去连接到
解决方案
推荐阅读
- python - 在 Jupyter Notebook 中,代码片段中错误输出的着色如何帮助我找出错误?
- javascript - 如何在 Google Chrome 中关闭 Preserve JavaScript console perseverance
- ansible - ansible Galaxy 角色的命令/模块名称与内置的 runit 模块冲突
- node.js - 从 Google Cloud Storage 获取绝对文件路径以用于 pdf-text-extract
- scala - 如何收集错误是scala,然后将它们全部放在一起
- asp.net-mvc - ASP.NET MVC / Core and Entity Framework 6 / Core - 配置和验证
- python - 字段值在列表中的 Django 查询集
- arrays - MongoDB具有唯一值的多个数组
- python - 在给定一条线的情况下找到周围的矩形区域
- ruby-on-rails - 将 has_many 更改为 has_and_belongs_to_many