import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* 解决跨域问题
*/
@Configuration
public class Cors extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH")
.allowCredentials(true).maxAge(3600);
}
}
spring boot 跨域
最新推荐文章于 2025-06-26 00:45:00 发布
本文介绍了一种在SpringBoot项目中解决跨域问题的方法,通过创建一个名为CorsextendsWebMvcConfigurerAdapter的配置类,允许所有源进行GET、POST、PUT等请求,并设置凭证允许及最大年龄。

323

被折叠的 条评论
为什么被折叠?



