SpringBoot2.0 (Fri) cors cross-domain

Source: Internet
Author: User

    • Partial cross-domain

@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

    • Global cross-domain

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.