angular springboot跨域访问
前端使用angular访问http://localhost:8080/people获取数据控制台显示XMLHttpRequest cannot load http://localhost:8080/people. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘htt
·
前端使用angular访问http://localhost:8080/people获取数据
控制台显示
XMLHttpRequest cannot load http://localhost:8080/people. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:4200’ is therefore not allowed access.
解决办法:
添加一个配置类,继承WebMvcConfigurerAdapter
重写addCorsMappings方法
@Configuration
public class CorsConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") //允许跨域访问的链接 "/**" 表示允许所有链接
.allowedMethods("*"); //允许的http方法(GET,PUT,POST,DELETE...),"*"表示允许所有方法
}
}
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐



所有评论(0)