亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在屬性文件中使用地圖

如何在屬性文件中使用地圖

精慕HU 2024-01-25 15:19:31
如何在屬性文件中映射它?我正在嘗試遵循Spring Cloud Gateway 上的此文檔然而,我們使用application.properties。spring:  cloud:    gateway:      globalcors:        corsConfigurations:          '[/**]':            allowedOrigins: "https://docs.spring.io"            allowedMethods:            - GET我嘗試了不同的變體但無濟于事:spring.cloud.gateway.globalcors.cors-configurations./**.allowed-originspring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-origin我得到一個例外:************************** 應用程序無法啟動描述:無法將“spring.cloud.gateway.globalcors.cors-configurations.allowed-origins”下的屬性綁定到org.springframework.web.cors.CorsConfiguration:Reason: No converter found capable of converting from type [java.lang.String] to type[org.springframework.web.cors.CorsConfiguration]行動:更新您的應用程序的配置請注意,此代碼使用 Spring Cloud Hoxton.M3。我理解,人們可能會認為 Spring 指南中的已知實現可能就是答案,但事實并非如此,因為 SC Gateway 不再使用 HttpServlet。更新:根據馬科斯·巴貝羅的說法,這有效。顯然,Eclipse 無法將此數據類型理解為屬性?,F在,您必須忽略解析錯誤。spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins=*spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods=*spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true
查看完整描述

2 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

我沒有嘗試過,但我認為你可以這樣使用它:

spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins="https://docs.spring.io"
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods[0]=GET

如果不起作用,請嘗試刪除[/**]結果中的方括號/**。


查看完整回答
反對 回復 2024-01-25
?
catspeake

TA貢獻1111條經驗 獲得超0個贊

您無法使用屬性文件設置這些屬性。而是使用 Spring 配置來設置這些屬性,如下所示:


@Bean

? ? public WebMvcConfigurer corsConfigurer() {

? ? ? ? return new WebMvcConfigurerAdapter() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void addCorsMappings(CorsRegistry registry) {

? ? ? ? ? ? ? ? registry.addMapping("/test-javaconfig").allowedOrigins("http://localhost:9000");

? ? ? ? ? ? }

? ? ? ? };

? ? }


查看完整回答
反對 回復 2024-01-25
  • 2 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號