0
点赞
收藏
分享

微信扫一扫

3种方式轻松解决SpringBoot跨域问题,你都用过么?

什么是跨域

当ajax请求的url中的传输协议、域名、端口号,有任意一个不同时,就会出现跨域请求

解决方案

一、注解解决

@CrossOrigin

二、配置解决

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.maxAge(1800)
.allowedOrigins("*");
}
}

三、 nginx解决

location / {
proxy_pass http://localhost:8080;
}
location /lglbc {
proxy_pass http://localhost:8848;
}


举报

相关推荐

0 条评论