2.添加跨域配置

CorsConfig

import org.springframework.context.annotation.Bean;
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 {

    @Bean
    public WebMvcConfigurer corsConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOriginPatterns("*")
                        .allowCredentials(true)
                        .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH")
                        .allowedHeaders("*")
                        .maxAge(3600);
                WebMvcConfigurer.super.addCorsMappings(registry);
            }
        };
    }
}

3.启动验证测试

百度首页测试
SpringBoot支持跨域请求

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2021-09-03
  • 2021-07-31
  • 2021-08-26
  • 2022-12-23
  • 2021-06-02
  • 2021-11-23
猜你喜欢
  • 2021-07-25
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案