spring boot 配置跨域问题

跨域

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private UserParameterResolver userParameterResolver;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(authInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

    @Override
    public void addArgumentResolvers(List argumentResolvers) {
        argumentResolvers.add(userParameterResolver);
        super.addArgumentResolvers(argumentResolvers);
    }
// 增加这句
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*");
    }
}

配置静态文件访问

spring:
  mvc:
    date-format: ${custom.common-date-format}
    static-path-pattern: "/**"

你可能感兴趣的:(spring boot 配置跨域问题)