No 'Access-Control-Allow-Origin' header is present on the requested resource.

这个问题是由前后端跨域引起的

解决方法:在后端配置

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 webConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("*")
                .allowedHeaders("*")
                .maxAge(3600);
    }
}
上一篇:Tomcat启动时报StandardServer.await: create[8005]: java.net.BindException: Cannot assign requested add...


下一篇:SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题