标签:let conf 跨域问题 text add http 返回 spring source
springmvc自带解决跨域问题的方法,需要在springboot中配置就可以解决跨域问题
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class LeyouCorsConfiguration {
@Bean
public CorsFilter corsFilter(){
//初始化cors配置对象
CorsConfiguration configuration=new CorsConfiguration();
//允许跨域的域名
configuration.addAllowedOrigin("http://manage.leyou.com");
configuration.setAllowCredentials(true);//允许携带cookie
configuration.addAllowedMethod("*");//代表所有的请求方法都支持,post、get、put、delete
configuration.addAllowedHeader("*");//允许携带任何头部信息
UrlBasedCorsConfigurationSource configurationSource=new UrlBasedCorsConfigurationSource();
configurationSource.registerCorsConfiguration("/**",configuration);
//返回corsFilter实例,参数:cors配置源对象
return new CorsFilter(configurationSource);
}
}
标签:let conf 跨域问题 text add http 返回 spring source
原文地址:https://www.cnblogs.com/ctupup/p/11808989.html