使用配置类实现WebMvcConfigur接口,配置全局跨域解决方案,
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
/* @Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**").excludePathPatterns("/user/**");
}*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOriginPatterns("*").allowCredentials(true).allowedHeaders("*").allowedMethods("*");
}
}
或者在接口层加入@CrossOrigin注解