跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教一下各位老哥 Cors 的配置问题
未分類
8 2 月 2021

请教一下各位老哥 Cors 的配置问题

请教一下各位老哥 Cors 的配置问题

資深大佬 : chenlee9876 0

Java 初学,在跟着网课搭网站 目前在学跨域这一块 这是我的配置文件

@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); 

在 idea 里 configSource 下面会报 error 错误提示

'org.apache.catalina.filters.CorsFilter' 中的 'CorsFilter()' 无法应用于 '(org.springframework.web.cors.UrlBasedCorsConfigurationSource)' 

请教下这个是啥意思啊 在网上搜了半天也找不到对应的问题(包括 Stackflow 这个问题是不是太基础了 我看别人都是这么写的啊= =

大佬有話說 (4)

  • 資深大佬 : chendy

    编译错误?
    CorsFilter 有俩
    你引了 org.apache.catalina.filters 下的
    需要 org.springframework.web.filter 下的

  • 資深大佬 : ardour

    node 项目里我倒是经常配 cors 让服务器裸奔解决跨域. java…恕我路过一下

  • 主 資深大佬 : chenlee9876

    @chendy 感谢老哥回复,确实是这个问题
    好新手的错误啊,学习了

  • 資深大佬 : liian2019

    补充下,addAllowedHeader 现在好像不支持*了,需要指明

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具