如何在屬性文件中映射它?我正在嘗試遵循Spring Cloud Gateway 上的此文檔然而,我們使用application.properties。spring: cloud: gateway: globalcors: corsConfigurations: '[/**]': allowedOrigins: "https://docs.spring.io" allowedMethods: - GET我嘗試了不同的變體但無濟(jì)于事:spring.cloud.gateway.globalcors.cors-configurations./**.allowed-originspring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-origin我得到一個(gè)例外:************************** 應(yīng)用程序無法啟動(dòng)描述:無法將“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]行動(dòng):更新您的應(yīng)用程序的配置請(qǐng)注意,此代碼使用 Spring Cloud Hoxton.M3。我理解,人們可能會(huì)認(rèn)為 Spring 指南中的已知實(shí)現(xiàn)可能就是答案,但事實(shí)并非如此,因?yàn)?SC Gateway 不再使用 HttpServlet。更新:根據(jù)馬科斯·巴貝羅的說法,這有效。顯然,Eclipse 無法將此數(shù)據(jù)類型理解為屬性?,F(xiàn)在,您必須忽略解析錯(cuò)誤。spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins=*spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods=*spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true
2 回答

喵喔喔
TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
我沒有嘗試過,但我認(rèn)為你可以這樣使用它:
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins="https://docs.spring.io" spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods[0]=GET
如果不起作用,請(qǐng)嘗試刪除[/**]
結(jié)果中的方括號(hào)/**
。

catspeake
TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊
您無法使用屬性文件設(shè)置這些屬性。而是使用 Spring 配置來設(shè)置這些屬性,如下所示:
@Bean
? ? public WebMvcConfigurer corsConfigurer() {
? ? ? ? return new WebMvcConfigurerAdapter() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void addCorsMappings(CorsRegistry registry) {
? ? ? ? ? ? ? ? registry.addMapping("/test-javaconfig").allowedOrigins("http://localhost:9000");
? ? ? ? ? ? }
? ? ? ? };
? ? }
添加回答
舉報(bào)
0/150
提交
取消