{"id":333143,"date":"2021-02-08T04:39:49","date_gmt":"2021-02-07T20:39:49","guid":{"rendered":"http:\/\/4563.org\/?p=333143"},"modified":"2021-02-08T04:39:49","modified_gmt":"2021-02-07T20:39:49","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%8b%e5%90%84%e4%bd%8d%e8%80%81%e5%93%a5-cors-%e7%9a%84%e9%85%8d%e7%bd%ae%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=333143","title":{"rendered":"\u8bf7\u6559\u4e00\u4e0b\u5404\u4f4d\u8001\u54e5 Cors \u7684\u914d\u7f6e\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u4e0b\u5404\u4f4d\u8001\u54e5 Cors \u7684\u914d\u7f6e\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenlee9876 <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Java \u521d\u5b66\uff0c\u5728\u8ddf\u7740\u7f51\u8bfe\u642d\u7f51\u7ad9 \u76ee\u524d\u5728\u5b66\u8de8\u57df\u8fd9\u4e00\u5757 \u8fd9\u662f\u6211\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>@Configuration public class CorsConfig {      public CorsConfig() {     }      @Bean     public CorsFilter corsFilter() {         CorsConfiguration config = new CorsConfiguration();         config.addAllowedOrigin(\"http:\/\/localhost:8080\");         config.setAllowCredentials(true);         config.addAllowedMethod(\"*\");         config.addAllowedHeader(\"*\");         UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();         configSource.registerCorsConfiguration(\"\/**\", config);         return new CorsFilter(configSource); <\/code><\/pre>\n<p>\u5728 idea \u91cc configSource \u4e0b\u9762\u4f1a\u62a5 error \u9519\u8bef\u63d0\u793a<\/p>\n<pre><code>'org.apache.catalina.filters.CorsFilter' \u4e2d\u7684 'CorsFilter()' \u65e0\u6cd5\u5e94\u7528\u4e8e '(org.springframework.web.cors.UrlBasedCorsConfigurationSource)' <\/code><\/pre>\n<p>\u8bf7\u6559\u4e0b\u8fd9\u4e2a\u662f\u5565\u610f\u601d\u554a \u5728\u7f51\u4e0a\u641c\u4e86\u534a\u5929\u4e5f\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u95ee\u9898\uff08\u5305\u62ec Stackflow \u8fd9\u4e2a\u95ee\u9898\u662f\u4e0d\u662f\u592a\u57fa\u7840\u4e86 \u6211\u770b\u522b\u4eba\u90fd\u662f\u8fd9\u4e48\u5199\u7684\u554a= =<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5237760\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chendy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7f16\u8bd1\u9519\u8bef\uff1f<br \/>CorsFilter \u6709\u4fe9<br \/>\u4f60\u5f15\u4e86 org.apache.catalina.filters \u4e0b\u7684<br \/>\u9700\u8981 org.springframework.web.filter \u4e0b\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5237761\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ardour <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             node \u9879\u76ee\u91cc\u6211\u5012\u662f\u7ecf\u5e38\u914d cors \u8ba9\u670d\u52a1\u5668\u88f8\u5954\u89e3\u51b3\u8de8\u57df. java&#8230;\u6055\u6211\u8def\u8fc7\u4e00\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5237762\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chenlee9876 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chendy \u611f\u8c22\u8001\u54e5\u56de\u590d\uff0c\u786e\u5b9e\u662f\u8fd9\u4e2a\u95ee\u9898<br \/>\u597d\u65b0\u624b\u7684\u9519\u8bef\u554a\uff0c\u5b66\u4e60\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5237763\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liian2019 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8865\u5145\u4e0b\uff0caddAllowedHeader \u73b0\u5728\u597d\u50cf\u4e0d\u652f\u6301*\u4e86\uff0c\u9700\u8981\u6307\u660e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u4e0b\u5404\u4f4d\u8001\u54e5 Cors \u7684\u914d\u7f6e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/333143"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333143"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/333143\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333143"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}