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 WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 拦截这些地址,使用跨域处理逻辑
registry.addMapping("/**")
// 可跨域的域名
.allowedOriginPatterns("http://localhost:8080")
// 支持跨域的请求
.allowedMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")
// 开启Cookie
.allowCredentials(true)
// 在限定时间内不需要预请求
.maxAge(60 * 60)
// 请求头包含那些数据时,支持跨域的功能
.allowedHeaders("*");
}
}
跨域配置类
最新推荐文章于 2024-05-05 13:21:29 发布