<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Content-Style-Type" content="text/css"/>
    <meta name="generator" content="Aspose.Words for .NET 15.1.0.0"/>
    <title>服务器跨域处理</title></head>
<body>
<div><p style="margin:0pt"><a name="_073-1565689474241"></a><span
        style="font-family:微软雅黑; font-size:15pt; font-weight:bold"><a href="http://m.zinglizingli.xyz">跨域处理</a></span>
</p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_011-1565689506880"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_400-1565689507090"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">跨域是什么？浏览器从一个域名的网页去请求另一个域名的资源时，域名、端口、 协议任一不同，都是跨域 。我们是采用前后端分离开发的，也是前后端分离部署的，必然会存在跨域问题。 怎么解决跨域？很简单，只需要在controller类上添加注解 @CrossOrigin 即可！这个注解其实是CORS的实现。 </span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_460-1565689522680"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">CORS(Cross-Origin Resource Sharing, 跨源资源共享)是W3C出的一个标准，其思 想是使用自定义的HTTP头部让浏览器与服务器进行沟通，从而决定请求或响应是应该成 功，还是应该失败。因此，要想实现CORS进行跨域，需要服务器进行一些设置，同时前端也需要做一些配置和分析。本文简单的对服务端的配置和前端的一些设置进行分析。</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_845-1565689480275"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_065-1565689480471"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">1️⃣</span><span
            style="color:#df402a; font-family:'Times New Roman'; font-size:11pt">在controller类上添加注解 @CrossOrigin，表示Controller上的所以方法允许跨域，在方法上添加注解 @CrossOrigin，表示该方法允许跨域</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_231-1565689931759"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_436-1565689932017"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">@Target({ ElementType.METHOD, ElementType.TYPE })</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_134-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">@Retention(RetentionPolicy.RUNTIME)</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_249-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">@Documented</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_993-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">public @interface CrossOrigin {</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_860-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_082-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] DEFAULT_ORIGINS = { "*" };</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_340-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_077-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] DEFAULT_ALLOWED_HEADERS = { "*" };</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_080-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_672-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    boolean DEFAULT_ALLOW_CREDENTIALS = true;</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_262-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_435-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    long DEFAULT_MAX_AGE = 1800;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_682-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_040-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_925-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_940-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 同origins属性一样</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_047-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_939-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    @AliasFor("origins")</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_774-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] value() default {};</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_570-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_575-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_114-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 所有支持域的集合，例如"http://domain1.com"。</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_373-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * &lt;p&gt;这些值都显示在请求头中的Access-Control-Allow-Origin</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_316-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * "*"代表所有域的请求都支持</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_011-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * &lt;p&gt;如果没有定义，所有请求的域都支持</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_880-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * @see #value</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_783-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_681-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    @AliasFor("value")</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_042-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] origins() default {};</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_140-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_747-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_226-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 允许请求头中的header，默认都支持</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_485-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_047-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] allowedHeaders() default {};</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_052-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_280-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_742-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 响应头中允许访问的header，默认为空</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_186-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_068-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String[] exposedHeaders() default {};</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_680-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_547-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_089-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 请求支持的方法，例如"{RequestMethod.GET, RequestMethod.POST}"}。</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_880-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 默认支持RequestMapping中设置的方法</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_922-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_840-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    RequestMethod[] methods() default {};</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_090-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_066-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_985-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 是否允许cookie随请求发送，使用时必须指定具体的域</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_972-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_119-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    String allowCredentials() default "";</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_127-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_478-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    /**</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_580-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     * 预请求的结果的有效期，默认30分钟</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_510-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">     */</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_534-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">    long maxAge() default -1;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_743-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_586-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">}</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_052-1565689932796"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_129-1565689558428"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_873-1565689558663"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">2️⃣</span><span
            style="color:#df402a; font-family:'Times New Roman'; font-size:11pt">配置 CorsFilter(全局配置)</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_025-1565690417616"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_510-1565690417783"></a><span
            style="background-color:#ffffff; color:#808000; font-family:SimSun; font-size:11pt">@Configuration</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_314-1565690418407"></a><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">public class </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">GlobalCorsConfig {</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_117-1565690418407"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_834-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">    </span><span
            style="background-color:#ffffff; color:#808000; font-family:SimSun; font-size:11pt">@Bean</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_074-1565690418407"></a><span
            style="background-color:#ffffff; color:#808000; font-family:SimSun; font-size:11pt">    </span><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">public </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">CorsFilter corsFilter() {</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_037-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//1.添加CORS配置信息</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_231-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">CorsConfiguration config = </span><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">new </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">CorsConfiguration();</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_560-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//1) 允许的域,不要写*，否则cookie就无法使用了</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_937-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">config.addAllowedOrigin(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"http://manage.shop.com"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_288-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedOrigin(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"http://www.shop.com"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_712-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//2) 是否发送Cookie信息</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_250-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">config.setAllowCredentials(</span><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">true</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_149-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//3) 允许的请求方式</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_028-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"OPTIONS"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_040-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"HEAD"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_940-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"GET"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_487-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"PUT"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_065-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"POST"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_034-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"DELETE"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_286-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        config.addAllowedMethod(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"PATCH"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_584-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">// 4）允许的头信息</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_339-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">config.addAllowedHeader(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"*"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_440-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">// 5) 有效时长</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_023-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//        config.setMaxAge(3600L);</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_025-1565690418407"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_612-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        //2.添加映射路径，我们拦截一切请求</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_816-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">UrlBasedCorsConfigurationSource configSource = </span><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">new </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">UrlBasedCorsConfigurationSource();</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_520-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        configSource.registerCorsConfiguration(</span><span
            style="background-color:#ffffff; color:#008000; font-family:SimSun; font-size:11pt; font-weight:bold">"/**"</span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">, config);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_929-1565690418407"></a><span
            style="font-family:'Times New Roman'; font-size:11pt">&#xa0;</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_591-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">        </span><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">//3.返回新的CorsFilter.</span>
    </p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_259-1565690418407"></a><span
            style="background-color:#ffffff; color:#808080; font-family:SimSun; font-size:11pt; font-style:italic">        </span><span
            style="background-color:#ffffff; color:#000080; font-family:SimSun; font-size:11pt; font-weight:bold">return new </span><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">CorsFilter(configSource);</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_877-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">    }</span></p>
    <p style="font-size:11pt; line-height:115%; margin:0pt 0pt 10pt"><a name="_415-1565690418407"></a><span
            style="background-color:#ffffff; font-family:SimSun; font-size:11pt">}</span></p></div>
</body>
</html>