解决跨域中 遇到的问题
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE","OPTIONS")
.maxAge(3600);
}
}
http://localhost:8081/book/findAll //后端访问地址 http://localhost:8080/book //前端访问地址
在刷新后端是报错
allowCredentials is true, allowedOrigins cannot contain the special
value "*" since that cannot be set on the
"Access-Control-Allow-Origin" response header. To allow credentials to
a set of origins, list them explicitly or consider using
"allowedOriginPatterns" instead.
经过一番查找 问题所在就是 .allowCredentials(true)。
把 **.allowCredentials(true)**删了就可以了
|