Failed to bind properties under 'spring.cloud.gateway.globalcors.cors-configurations.allowedorigins' to org.springframework.web.cors.CorsConfiguration:
Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.web.cors.CorsConfiguration]
Action:
Update your application's configuration
出现这个错误通常是因为在配置文件中未正确设置
spring.cloud.gateway.globalcors.cors-configurations.allowedorigins属性。allowedorigins应该是一个字符串列表,包含允许的来源站点。确保在配置文件(如
application.properties或application.yml)中正确设置了该属性。例如,在application.yml文件中设置允许的来源站点:如果你在 Java 配置类中进行配置,可以使用以下方式:
@Configurationpublic class GatewayConfig { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowedOrigins(Arrays.asList("https://example.com", "https://example2.com")); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } }