【发布时间】:2020-08-06 04:29:02
【问题描述】:
我正在使用 application.properties 和我的 linux 环境来获得一些 12 因素的好处。我正在尝试获取一个 api 密钥来为我定义的自定义 application.properties 值工作,但它不起作用。
# application.properties
plenti.iaphub.webhooks.key=ACTUAL_VALUE_OF_API_KEY # This one works
# application.properties
plenti.iaphub.webhooks.key=${ENV_VARIABLE_HOLDING_API_KEY} # This one doesn't work
这是我尝试访问该值的方式
@Controller
@RequestMapping(path = "/iap")
public class IAPHUBController {
@Autowired
Environment env;
@PostMapping(path = "/webhook")
public ResponseEntity<String> webhook(@RequestHeader("X-Auth-Token") String iapAuthHeader) {
String iaphubKey = env.getProperty("plenti.iaphub.webhooks.key");
if (!iapAuthHeader.equals(iaphubKey)) {
// this is an inauthentic request
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
return ResponseEntity.ok("Hello IAPHUB");
}
}
这是我尝试访问 ENV 变量版本时遇到的错误
java.lang.IllegalArgumentException: Could not resolve placeholder
【问题讨论】:
标签: spring spring-boot environment-variables application.properties