跨域访问

package com.ctd.cloud.knowledge.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**

  • Created by user on 2019/8/22.

  • 添加支持CORS跨域访问

  • /
    @Configuration
    public class CrossDomainConfiguration implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {

      registry
              .addMapping("/**")  //配置可以被跨域的路径,可以任意配置,可以具体到直接请求路径
              .allowedMethods("*")           //允许所有的请求方法访问该跨域资源服务器,如:POST、GET、PUT、DELETE等
              .allowedOrigins("*")           //允许所有的请求域名访问我们的跨域资源,可以固定单条或者多条内容
              .allowedHeaders("*");          //允许所有的请求header访问,可以自定义设置任意请求头信息

    }
    }

全部评论

相关推荐

牛客604067584号:我9月初投递10月入池,泡到现在。hr全部离职,当然没离职的时候也联系不上。我发邮件给campus也不回我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务