跨域
package com.sf.vsolution.hb.core;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("http://10.79.17.26:9005");
config.addAllowedOrigin("http://10.79.23.50:9005");
config.addAllowedOrigin("http://10.79.23.70:9004");
config.addAllowedOrigin("http://121.37.13.83:31825");
config.addAllowedOrigin("http://139.9.62.103");
config.addAllowedOrigin("https://baidu.com");
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setMaxAge(3600L);
config.setAllowCredentials(true);
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
}