Spring boot 遇到前端报错Access-Control-Allow-Origin 跨域问题

前端报错 Access-Control-Allow-Origin 的前端问题解决:

在spring boot 服务中心添加一个配置文件:

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

    @Override  
    public void addCorsMappings(CorsRegistry registry) {  
        registry.addMapping("/**")  
                .allowedOrigins("*")  
                .allowCredentials(true)  
                .allowedMethods("GET", "POST", "DELETE", "PUT")  
                .maxAge(3600);  
    }  

}  


 
  
 
  

你可能感兴趣的:(Spring boot 遇到前端报错Access-Control-Allow-Origin 跨域问题)