![](https://img-blog.csdnimg.cn/direct/90bcf5fd54f4481cbffeda31d3ae1d9b.png)
1. 使用nginx部署同一个域
![](https://img-blog.csdnimg.cn/direct/d03c893354cf425f879cc58ebdcfea42.png)
2. 通过使用配置类方式解决跨域问题
![](https://img-blog.csdnimg.cn/direct/95a52b234bc04aabbed2dc7828165d10.png)
配置类
@Configuration
public class AppCorsConfiguration {
@Bean
public CorsWebFilter corsWebFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
//配置跨域
//允许请求头跨域
corsConfiguration.addAllowedHeader("*");
//允许请求方式跨域
corsConfiguration.addAllowedMethod("*");
//允许请求来源进行跨域
corsConfiguration.addAllowedOrigin("*");
//允许携带cookie跨域
corsConfiguration.setAllowCredentials(true);
//public void registerCorsConfiguration(String path, CorsConfiguration config)
source.registerCorsConfiguration("/**",corsConfiguration);
return new CorsWebFilter(source);
}
}