我的 Grails 中有一个特定于环境的标头属性application.yml
,配置如下:
environments:
development:
apiKey: 'foo'
如何@Header
在 micronaut HTTP 声明式客户端中使用此设置?
我试过这个:
// property placeholder resolver seems to interprept 'apiKey' property as 'api-key'
@Header(name = 'apikey', value = '${api-key}')
但我收到了这个错误:
io.micronaut.context.exceptions.ConfigurationException: Could not resolve placeholder ${api-key}
at io.micronaut.context.env.DefaultPropertyPlaceholderResolver$PlaceholderSegment.getValue(DefaultPropertyPlaceholderResolver.java:283)
at io.micronaut.context.env.DefaultPropertyPlaceholderResolver.resolveRequiredPlaceholders(DefaultPropertyPlaceholderResolver.java:95)
at io.micronaut.inject.annotation.EnvironmentAnnotationValue.lambda$new$0(EnvironmentAnnotationValue.java:48)
at io.micronaut.core.annotation.AnnotationValue.getRawSingleValue(AnnotationValue.java:953)
at io.micronaut.core.annotation.AnnotationValue.stringValue(AnnotationValue.java:482)
at io.micronaut.core.annotation.AnnotationValue.stringValue(AnnotationValue.java:514)
at io.micronaut.http.client.interceptor.HttpClientIntroductionAdvice.intercept(HttpClientIntroductionAdvice.java:207)
此外,并非所有环境都需要此标头(在这种情况下,它将设置为空字符串)。@Header 会处理这个吗?还是我需要做一些不同的事情?