首页 > 编程语言 > 详细

springboot 跨域

时间:2018-03-15 15:49:28      阅读:234      评论:0      收藏:0      [点我收藏+]

1. 添加关于CORS的端点配置,默认情况下是禁用的,通过以下配置打开

endpoints.cors.allowed-origins=http://www.xxx.com

endpoints.cors.allowed-methods=GET,POST,PUT,DELETE

2. 添加@CrossOrigin注解来实现跨域

3. 方法配置

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter{
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        
        registry.addMapping("/**")
        .allowedOrigins("http://www.www.com")
        .allowedMethods("GET","POST","PUT","DELETE");
    }
}

实际上,spring 4.2 以后才支持CORS。

springboot 跨域

原文:https://www.cnblogs.com/yangfei-beijing/p/8573757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!