package com.atguigu.config; import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Component public class WebMvcConfiguration implements WebMvcConfigurer { /** * * 解决跨域 * * @param registry 跨域注册表 */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**")// 添加路径规则 .allowCredentials(true)// 是否允许在跨域的情况下传递Cookie .allowedOriginPatterns("*")// 允许请求来源的域规则 .allowedMethods("*") .allowedHeaders("*");// 允许所有的请求头 } }