【问题标题】:Should I wrap @ConfigProperty fields in a javax.enterprise.inject.Instance object?我应该将@ConfigProperty 字段包装在 javax.enterprise.inject.Instance 对象中吗?
【发布时间】:2021-06-20 13:44:11
【问题描述】:

在我的 quarkus 项目中,我在过滤器(ContainerRequestFilter、ContainerResponseFilter)中注入了几个 ConfigProperty。 这在启动时给了我以下警告:

[io.qua.res.com.dep.ResteasyCommonProcessor] (build-46) Directly injecting a @ConfigProperty into a JAX-RS provider may lead to unexpected results. To ensure proper results, please change the type of the field to javax.enterprise.inject.Instance<java.lang.String>. Offending field is 'fieldName' of class 'className'  

[io.qua.res.com.dep.ResteasyCommonProcessor] (build-46) Directly injecting a @ConfigProperty into a JAX-RS provider may lead to unexpected results. To ensure proper results, please change the type of the field to javax.enterprise.inject.Instance<java.util.List<java.lang.String>>. Offending field is 'fieldName' of class 'className'

但是,configuration guide 从未提及这一点,甚至显示an example 在 JAX-RS 资源中注入 ConfigProperty。

此外,尽管有警告,但一切正常。 所以我的问题是:我应该关心这个警告并应用它的建议还是可以忽略它?为什么指南中没有提到这一点(无论是简短的,还是reference 的)

我使用的是 quarkus 1.12.2,但之前的版本也有“问题”。

【问题讨论】:

    标签: quarkus eclipse-microprofile-config


    【解决方案1】:

    该警告仅针对 JAX-RS 提供者显示,而不针对 JAX-RS 资源显示。

    我建议您先发出警告 - 但正如我上面提到的,只对提供者进行更改(如您提到的过滤器)

    【讨论】:

      猜你喜欢
      • 2022-11-06
      • 1970-01-01
      • 2012-06-14
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 2021-11-03
      相关资源
      最近更新 更多