一:添加配置文件
```java
@Configuration
public class CorsConfig {
public CorsFilter corsFilter(){
//1.添加cors 配置信息
CorsConfiguration config=new CorsConfiguration();
config.addAllowedOrigin("localhost:80");
config.setAllowCredentials(true);//cookie信息是否发送
config.addAllowedMethod("*");//设置请求方式
config.addAllowedHeader("");//设置允许的header
//2. url 添加映射
UrlBasedCorsConfigurationSource corsSourse=new UrlBasedCorsConfigurationSource();
corsSourse.registerCorsConfiguration("/**",config);
//2.返回新的corsSourse
return new CorsFilter(corsSourse) ;
}
}
详细参看如下:
浅谈CSRF攻击方式:
https://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html
https://www.jianshu.com/p/b0923f6b3541
https://www.cnblogs.com/collin/articles/9637999.html
跨域问题详解:https://segmentfault.com/a/1190000015597029?utm_source=tag-newest