根据操作系统,可能不允许使用该密钥,但选项之一是使用SPRING_APPLICATION_JSON。检查externalize configuration。
假设您有以下属性
spring:
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedHeaders: "*"
allowedMethods:
- GET
- POST
将此 yaml 转换为 json。对于eg
{
"spring": {
"cloud": {
"gateway": {
"globalcors": {
"corsConfigurations": {
"[/**]": {
"allowedOrigins": "*",
"allowedHeaders": "*",
"allowedMethods": [
"GET",
"POST"
]
}
}
}
}
}
}
}
修剪eg using 的所有空格
{"spring":{"cloud":{"gateway":{"globalcors":{"corsConfigurations":{"[/**]":{"allowedOrigins":"*","allowedHeaders":"*","allowedMethods":["GET","POST"]}}}}}}}
现在在您的环境变量中,您可以设置
SPRING_APPLICATION_JSON = "{"spring":{"cloud":{"gateway":{"globalcors":{"corsConfigurations":{"[/**]":{"allowedOrigins":"*","allowedHeaders":"*","allowedMethods":["GET","POST"]}}}}}}}"
您可以编写某种 CLI 脚本来执行此操作。