SpringBoot解决跨域问题

来源:互联网 发布:淘宝网计生用品 编辑:程序博客网 时间:2024/05/29 09:25

之前写php和python的时候都是通过添加header来实现跨域的,现在用springboot猛一遇到这个问题还真有点懵,不知道该怎么加了,所以在网上找了些解决方案:


package cn.ac.yangge.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@Configurationpublic class CrossDomain extends WebMvcConfigurerAdapter {    @Override    public void addCorsMappings(CorsRegistry registry) {        registry.addMapping("/**").allowedOrigins("*")                .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")                .allowCredentials(false).maxAge(3600);    }}


原创粉丝点击