简体   繁体   English

我应该将@ConfigProperty 字段包装在 javax.enterprise.inject.Instance object 中吗?

[英]Should I wrap @ConfigProperty fields in a javax.enterprise.inject.Instance object?

In my quarkus project I inject several ConfigProperty in filters (ContainerRequestFilter, ContainerResponseFilter).在我的 quarkus 项目中,我在过滤器(ContainerRequestFilter、ContainerResponseFilter)中注入了几个 ConfigProperty。 This gives me the following warning on startup:这在启动时给了我以下警告:

[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'

However, the configuration guide never mentions this and even shows an example of injecting ConfigProperty in a JAX-RS resource.但是,配置指南从未提及这一点,甚至显示了在 JAX-RS 资源中注入 ConfigProperty 的示例

Also, despite the warning, everything works fine.此外,尽管有警告,但一切正常。 So my question is: should I care about this warning and apply its advice or can I ignore it?所以我的问题是:我应该关心这个警告并应用它的建议还是可以忽略它? Why is there no mention of this in the guides (neither the short one, nor the reference one)为什么指南中没有提到这一点(无论是简短的,还是参考的)

I'm using quarkus 1.12.2 but I had the "issue" with previous versions too.我正在使用 quarkus 1.12.2,但我也遇到了以前版本的“问题”。

The warning is only shown for JAX-RS Providers, not JAX-RS Resources.该警告仅针对 JAX-RS 提供者显示,而不针对 JAX-RS 资源显示。

I would suggest you do head the warning - but as I mentioned above only make the change for Providers (like the filters you mention)我建议您确实发出警告-但正如我上面提到的,仅对提供者进行更改(例如您提到的过滤器)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM