美文网首页
spring boot 配置跨域问题

spring boot 配置跨域问题

作者: huangxiongbiao | 来源:发表于2017-09-05 08:20 被阅读36次

跨域

@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<HandlerMethodArgumentResolver> 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 配置跨域问题

      本文链接:https://www.haomeiwen.com/subject/xzayjxtx.html