package com.imooc.config;
import org.springframework.context.annotation.Bean;
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 CorsConfig {
public CorsConfig() {
}
@Bean
public CorsFilter corsFilter() {
// 1. 添加cors配置信息
CorsConfiguration config = new CorsConfiguration();
// 设置是否发送cookie信息
config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:8080");
config.addAllowedOrigin("http://192.168.3.16"); // 前端地址80端口
config.addAllowedOrigin("http://192.168.3.16:9999"); // 前端地址9999端口
// 设置允许请求的方式
config.addAllowedMethod("*");
// 设置允许的header
config.addAllowedHeader("*");
// 2. 为url添加映射路
Spring boot配置Cors 指定ip跨域失效解决方法
最新推荐文章于 2023-06-03 22:40:32 发布