本文介绍了如何在球衣2.0中用hk2注入常数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在球衣中使用HK2注入一个常数?有了Guice,我可以有一些类,如

  public class DependsOnFoo {

@Inject
public DependsOnFoo(@Named(FOO)String foo){
...
}
...
}
/ pre>

,我将在注入器中配置一些类似于

  bind(String.class).named(FOO)toInstance(new String(foo))

HK2中的等价物(如果有的话)是什么?

解决方案





这些电话底层有东西,但这可能是最简单的。


How do I inject a constant into some class using HK2 in jersey? With Guice I could have some class like

public class DependsOnFoo {

    @Inject
    public DependsOnFoo(@Named("FOO") String foo) {
        ...
    }
    ...
}

and I would configure it in the injector with something like

bind(String.class).named("FOO").toInstance(new String("foo"))

What's the equivalent, if any, in HK2?

解决方案

One Way

Another Way

There is stuff underlying these calls, but this is probably the easiest.

这篇关于如何在球衣2.0中用hk2注入常数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 13:35