Springboot 2.0 front-end cross-domain static resource local mapping

Source: Internet
Author: User

Because in the Springboot 2.0 Webmvcautoconfigurationadapter this class becomes an automatic configuration class if you want to integrate many of the properties of this class autoconfiguration will fail, which means that the class has expired you need to use

Interface to implement local mapping of static resources and a series of functions such as front-end cross-domain

@Configuration Public classWebappconfigImplementsWebmvcconfigurer {/** Static Resource Local mapping * IMG is virtual path * mapped to local D-Disk javaspace under Tomcatpath * Browser access: localhost:8080/img/xxx file **/     Public voidaddresourcehandlers (Resourcehandlerregistry registry) {Registry.addresourcehandler ("/img/**"). Addresourcelocations ("file:d:/javaspace/tomcatpath/"). Setcacheperiod (31556926); }    //front-end cross-domain     Public voidaddcorsmappings (Corsregistry registry) {registry.addmapping ("/**")//set the path allowed across domains. Allowedorigins ("*")//set up domain names that allow cross-domain requests. Allowcredentials (true)//whether to allow certificates to no longer be turned on by default. Allowedmethods ("GET", "POST", "PUT", "DELETE")//to set allowed methods. MaxAge (3600);//allow time across domains    }}

Springboot 2.0 front-end cross-domain static resource local mapping

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.