如何在micronaut客户端@Header中使用Grails环境设置? [英] How do I use the Grails environment settings in micronaut client @Header?

查看:184
本文介绍了如何在micronaut客户端@Header中使用Grails环境设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Grails application.yml中有一个特定于环境的标头属性,其配置如下:

I have an environment-specific header property in my Grails application.yml, configured like so:

environments:
    development:
        apiKey: 'foo'

如何为Micronaut HTTP声明性客户端在@Header中使用此设置?

How do I use this setting in a @Header for the micronaut HTTP declarative client?

我尝试过:

// 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)

此外,不一定在所有环境中都需要此标头(在这种情况下,它将被设置为空字符串). @Header可以处理吗?还是我需要做些不同的事情?

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不支持在application.yml中读取environments.development.如果将配置移到application-development.yml,则Grails和Micronaut都将读取它.

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.

这篇关于如何在micronaut客户端@Header中使用Grails环境设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆