How do I use the Grails environment settings in micronaut client @Header?

旧城冷巷雨未停 提交于 2020-04-18 03:21:24

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/60662175/how-do-i-use-the-grails-environment-settings-in-micronaut-client-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!