【问题标题】:Are there any differences for @Context injected on a Class or a Method?在类或方法上注入的@Context 有什么不同吗?
【发布时间】:2019-05-29 19:02:54
【问题描述】:

在 JAX-RS 中,我们可以将 @Context 实例注入 HttpServletRequest 作为类字段或方法参数。

这两个选项有什么不同吗?

我相信单身人士会注入某种代理,但有什么副作用需要注意吗?还是它们是透明的,只是个人喜好问题?

【问题讨论】:

    标签: jersey jax-rs jersey-2.0


    【解决方案1】:

    在大多数情况下,这只是个人喜好。

    我的建议是作为类字段注入,因为 @Context 注释最终将被 CDI 中的 @Inject 替换 - 而 @Inject 注释不针对方法参数。你可以read more of the discussion here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      • 2011-01-29
      • 2013-07-20
      相关资源
      最近更新 更多