HK2 annotations not being handled

大憨熊 提交于 2019-12-04 17:28:56

There is a method on ServiceLocatorUtilities called addClasses

So get access to the ServiceLocator and just do

ServiceLocatorUtilities.addClasses(locator, ShouldHaveSingletonScope.class);

The binders are very literal, and will only do what you tell it as opposed to looking at the classes directly.

This should work:

bindAsContract(ShouldHaveSingletonScope.class).in(Singleton.class);

You can either configure the locator manually using Binder

-or-

use hk2 annotations, run hk2-inhabitants-generator (see hk2 doc) which will generate META-INF/hk2-locator/default file, then you will need to create your own ComponentProvider (see jersey doc) to populate service locator from that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!