我在Java SE应用程序中使用Jersey。 HK2为整个应用程序提供依赖项注入。 HK2 RunLevel服务已注册在应用程序服务定位器中,该应用程序定位器是Jerseys服务定位器的父级。
+ application locator
|\- RunLevel capabilities
| - MyCustomService, @RunLevel(value=1)
\
+ jersey locator
\- jersey resource class
\ @Inject MyCustomService
我的问题是我无法从Jersey内访问运行级别范围的服务。当-在以上示例中-球衣资源打开时,MyCustomService
的注入失败:
java.lang.IllegalStateException:找不到org.glassfish.hk2.runlevel.RunLevel的活动上下文
原因似乎是HK2 RunLevel功能背后的服务具有可见性LOCAL:球衣定位器无法通过其父定位器访问它们。参见here。
问题:
带有子级和RunLevelService的想法是,实际的RunLevelServices将是精简服务,在父级中协调真正服务的启动。而且,一个进程中的多个“子系统”可能具有不同的RunLevelService“隔离专区”,每个“隔离专区”都是其父级的子级。