如何将其映射到属性文件中?
我试图在Spring上跟踪这份文件
然而,我们是application.properties。
spring:
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "https://docs.spring.io"
allowedMethods:
- GET我尝试过不同的变体,但都没有用:
spring.cloud.gateway.globalcors.cors-configurations./**.allowed-origin
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-origin我有个例外:
*申请启动失败
描述:
未能将'spring.cloud.gateway.globalcors.cors-configurations.allowed-origins‘下的属性绑定到org.springframework.web.cors.CorsConfiguration:
原因:没有发现能够从java.lang.String类型转换为类型的转换器
org.springframework.web.cors.CorsConfiguration
操作:
更新应用程序的配置
请注意,此代码使用的是Spring Hoxton.M3。我理解,人们可能会认为,根据Spring已知的实现可能是答案,但事实并非如此,因为SC网关不再使用HttpServlet了。
更新:根据Marcos Barbero的说法,这是可行的。显然,Eclipse不能将此数据类型理解为属性。现在,您必须处理忽略解析错误。
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins=*
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods=*
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true发布于 2019-11-05 15:36:10
我没试过,但我想你可以这样用:
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins="https://docs.spring.io"
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods[0]=GET如果它不起作用,请尝试从[/**]中删除导致/**的方括号。
发布于 2019-11-01 06:04:26
不能使用propeties文件设置这些属性。相反,可以使用Spring配置来设置这些属性,如下所示:
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/test-javaconfig").allowedOrigins("http://localhost:9000");
}
};
}此外,这帖子可能会有所帮助。
https://stackoverflow.com/questions/58654673
复制相似问题