@CrossOrigin annotations Support the class level, which is added at the method level. Can be added on a controller class or method, supporting partial interfaces across domains. When both are added, the method level overrides the class-level.
Property |
Description |
Origins |
List of allowed domains, "*" means all domains are supported |
MaxAge |
Maximum duration of the pre-response cache, in seconds |
Allowedheaders |
The list of request headers allowed in the actual request, "*" means all headers are allowed |
Exposedheaders |
In the response header, set the client-visible header, which is not a common cache-control,content-language, etc., the header set here is from the " Access-control-expose-headers "in. |
Methods |
Supported collection of HTTP request methods |
Allowcredentials |
Sets whether to send the voucher, which is set on the "Access-control-max-age" of the pre-requested response. This value determines whether the browser needs to send credentials when a cross-domain request is initiated. False-cookies should not be included; ""-means undefined, allowing all values; true-pre-response will include a header with a value set to True Access-control-allow-credentials |
Under the SPRINGBOOT project environment, declare the following bean:
@Configuration
public class Configservice {
@Bean
Public Webmvcconfigurer Corsconfigurer ()
{
return new Webmvcconfigurer () {
@Override
public void Addcorsmappings (Corsregistry registry) {
Registry.addmapping ("/**"). Allowedorigins ("*"). Allowedmethods ("*"). Allowcredentials (True);
}
};
}
}
Global cross-domain is supported.
SpringBoot2.0 (Fri) cors cross-domain