- 跨域文件配置
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.reactive.CorsWebFilter; import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; import org.springframework.web.server.WebFilter; import org.springframework.web.util.pattern.PathPatternParser; /** * @author: nql * @Description:解决跨域问题。 * @date: */ @Configuration @Order(Ordered.HIGHEST_PRECEDENCE + 1) public class RouteConfiguration { private static final String ALLOWED_HEADERS = "*"; private static final String ALLOWED_METHODS = "*"; private static final String ALLOWED_ORIGIN = "*"; @Bean public WebFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.addAllowedMethod(ALLOWED_METHODS); config.addAllowedOrigin(ALLOWED_ORIGIN); config.addAllowedHeader(ALLOWED_HEADERS); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); source.registerCorsConfiguration("/**", config); return new CorsWebFilter(source); } }
Java 解决跨域问题
最新推荐文章于 2024-01-26 13:00:42 发布