SpringBoot + Vue 前后端跨域问题

1、报错信息

java.lang.IllegalArgumentException: When 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.

2、解决方案:

(1)若在后端项目中配置有跨域设置的WebMvc配置类,将其中的addOrigins("*")换成addPathOrigins("*")。​

(2)若在后端项目中未配置跨域的WebMvc配置类,则检查控制类是否添加有@CrossOrigin。需要在Controller类上添加注解@CrossOrigin。

注意:后端配置跨域有两种方式:(二者选一即可)

(1)配置WebMvc配置类;

(2)直接在Controller类上加上注解@CrossOrigin。

注意: 两者都有配置,可能还是会报错。建议两种配置选择其中一者即可。

你可能感兴趣的:(SpringBoot与Vue,spring,boot,vue.js,java)