- 新增CorsFilter
@Configuration @Slf4j public class CorsConfig { @Autowired private YangProperties yangProperties; @Bean public CorsFilter corsFilter(){ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfig = yangProperties.getCors(); corsConfig.addAllowedOrigin("*"); corsConfig.addAllowedHeader("*"); corsConfig.addAllowedMethod("*"); corsConfig.setAllowCredentials(true); log.info("Registering Cors filter"); source.registerCorsConfiguration("/**", corsConfig); return new CorsFilter(source); } }
-
在WebSecurityConfigurerAdapter的实现类中重新configure(WebSecurity web)方法
@Override public void configure(WebSecurity web) throws Exception { web.ignoring() .antMatchers(HttpMethod.OPTIONS, "/**"); //结局跨域问题 }
SpringBoot实现跨域请求
最新推荐文章于 2024-08-01 08:00:00 发布