@Configuration public class GlobalCorsConfig { @Bean public CorsFilter corsFilter () { // 1. Add CORS configuration information CorsConfiguration config = new new CorsConfiguration (); // 1) allows a domain, do not write *, otherwise the cookie will not be used config.addAllowedOrigin ( "http: //127.0 .0.1: 6001 " ); config.addAllowedOrigin ( "HTTP: // localhost: 6001" ); // 2) whether to transmit the Cookie information config.setAllowCredentials ( to true ); // . 3) allows the request type config.addAllowedMethod ( "the OPTIONS" ); config.addAllowedMethod("HEAD"); config.addAllowedMethod("GET"); config.addAllowedMethod("PUT"); config.addAllowedMethod("POST"); config.addAllowedMethod("DELETE"); config.addAllowedMethod ( "the PATCH" ); // . 4) allows the header information config.addAllowedHeader ( "*" ); // 2. Add map path, we intercept all requests UrlBasedCorsConfigurationSource the configSource = new new UrlBasedCorsConfigurationSource(); configSource.registerCorsConfiguration ( "/ **" , config); // 3. return new CorsFilter. return new new CorsFilter (the configSource); } }
springboot Tim solve cross-domain configuration class problem
Guess you like
Origin www.cnblogs.com/bigbigxiao/p/12128801.html
Recommended
Ranking