当前位置: 首页 > 工具软件 > Poli > 使用案例 >

el-upload报错Access to XMLHttpRequestthttpxxxx‘ from origin ‘httpxxxx‘ has been blocked by CORS poli

叶炜
2023-12-01
package com.example.demo.config;

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 CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//本应用的所有方法都会去处理跨域请求
        registry.addMapping("/**")
//允许远端访问的域名
                .allowedOrigins("http://localhost:9876")//这个地址是你所配得前台地址
//允许请求的方法("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .allowedMethods("*")
//允许请求头
                .allowedHeaders("*");
    }
}
 类似资料: