**
springboot全局跨域和解决方案
**
- 什么是跨域?
当一个请求url的协议,域名和端口任意一个与当前的url不同即为跨域
2.解决方案
新建java文件,将下列代码复制即可完成
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowCredentials(true)
.allowedOrigins("*")
.allowedMethods(new String[]{"GET","POST","PUT","DELETE"})
.allowedHeaders("*");
}
}