springboot前后端访问出现跨域问题的后端最终解决方案
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
) {
System
.out
.println("我是MyWebConfig跨域");
registry
.addMapping("/**")
.allowedOrigins("*")
//是否允许证书 不再默认开启
.allowCredentials(true)
//设置允许的方法
.allowedMethods("*")
//跨域允许时间
.maxAge(3600);
}
}
转载请注明原文地址: https://lol.8miu.com/read-15682.html