springboot后台解决跨域问题

直接上代码

 

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

/*
* 解决跨域问题
* */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

public void addCorsMappings(CorsRegistry registry) {
System.out.println("--- 解决跨域问题 ---");
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowCredentials(true);//允许验证
}

}
posted @ 2020-12-17 09:45  tomsen_jin  阅读(134)  评论(0编辑  收藏  举报