@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
/**
* 1. 允许访问路径
* 2. 添加跨域请求来源
* 3. 允许跨域的方法
* 4. 允许携带信息
* 5. 最大响应时间
*/
registry.addMapping("/**")
.allowedOrigins("http://localhost:8888", "null")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowCredentials(true)
.maxAge(3600);
}
}
Spring Boot跨域配置
于 2022-01-28 19:16:46 首次发布