I have an environment-specific header property in my Grails application.yml
, configured like so:
environments:
development:
apiKey: 'foo'
How do I use this setting in a @Header
for the micronaut HTTP declarative client?
I tried this:
// property placeholder resolver seems to interprept 'apiKey' property as 'api-key'
@Header(name = 'apikey', value = '${api-key}')
but I got this error:
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)
Also, this header may not be needed in all environments (in this case, it will be set to the empty string). Will the @Header handle this? Or do I need to do something different?
Micronaut doesn't support reading environments.development
in application.yml. If you move your config to application-development.yml
then it will be read by both Grails and Micronaut.