更新时间:2022-12-13 11:47:40
JAX-RS规范并未强制要求Apache
Wink提供的行为。 IOW,您尝试使用的功能适用于Apache Wink
,使您的代码不可移植。
JAX-RS specification does not mandate the behavior provided by Apache Wink. IOW, the feature you are trying to use that works on Apache Wink makes your code non-portable.
要生成100%JAX-RS可移植代码,你需要注入
javax.ws.rs.ext.Providers实例,然后使用:
To produce 100% JAX-RS portable code, you need to inject javax.ws.rs.ext.Providers instance and then use:
ContextResolver<MyContext> r = Providers.getContextResolver(MyContext.class, null);
MyContext ctx = r.getContext(MyContext.class);
检索你的MyContext实例。
to retrieve your MyContext instance.
在Jersey中,你也可以直接注入ContextResolver,
,它可以从上面保存一行代码,但请注意,这个
策略也不是100%可移植的。
In Jersey, you can also directly inject ContextResolver, which saves you one line of code from the above, but note that this strategy is also not 100% portable.