Questions about cross-domain SpringBoot

Add this piece of code directly on the line in the startup class inside:

@Bean   
    public CorsFilter corsFilter () {   
        Final UrlBasedCorsConfigurationSource new new UrlBasedCorsConfigurationSource = Source ();   
        Final CorsConfiguration new new CorsConfiguration config = ();   
        config.setAllowCredentials (to true); // allow cross-domain cookies   
        config.addAllowedOrigin ( "*"); // # commit request to allow server URI, * represents all allowed, in SpringMVC if * is set to automatically switch to the current request header Origin   
        config.addAllowedHeader ( "*"); // # allow access to the head of information, * means all   
        config.setMaxAge (18000L); // preflight request buffer time (in seconds), i.e., in this time period, the same cross-domain request will not be the preflight   
        config.addAllowedMethod ( "OPTIONS" ); // method allowing to submit the request, * represents all allowed   
        config.addAllowedMethod ( "the HEAD");    
        config.addAllowedMethod ( "the GET"); // request method allows the Get  
        config.addAllowedMethod ( "the PUT");   
        config.  addAllowedMethod("POST");  
        config.addAllowedMethod("DELETE");  
        config.addAllowedMethod("PATCH");  
        source.registerCorsConfiguration("/**", config);  
        return new CorsFilter(source);  
    }  

  

Guess you like

Origin www.cnblogs.com/ZJOE80/p/11117905.html