做前端H5的时候。请求另外一个服务器上的数据。用抓包工具发现已经请求成功,且有数据返回。但是在谷歌F12打开之后。发现没有返回;且报错No 'Access-Control-Allow-Origin' header is present on the requested 。经查看博客。发现解决方法
public class Application extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowCredentials(true)
.allowedHeaders("*")
.allowedOrigins("*")
.allowedMethods("*");
}
在启动类application中修改这样之后。就可访问成功。
来源:https://blog.youkuaiyun.com/qq779446849/article/details/53102925