我有一个与这里提出的问题类似的问题:如何让我的 Jersey 2 端点在启动时急切地初始化?
但稍微往下走。我可以立即加载我的资源,但是当我尝试通过调用 REST url 来使用它时,我得到以下堆栈跟踪。
java.lang.IllegalStateException: Could not find an active context for org.glassfish.hk2.api.Immediate
2. java.lang.IllegalStateException: While attempting to create a service for
SystemDescriptor(
implementation=com.service.MyResource
contracts={com.service.MyResource}
scope=org.glassfish.hk2.api.Immediate
qualifiers={}
descriptorType=CLASS
descriptorVisibility=NORMAL
metadata=
rank=0
loader=null
proxiable=null
proxyForSameScope=null
analysisName=null
id=150
locatorId=0
identityHashCode=1249600275
reified=true) in scope org.glassfish.hk2.api.Immediate an error occured while locating the context
我的 TResource 类是这样注释的:
@Immediate
@Path("/test/v1")
public class TResource {
我的基于 Grizzly 的服务器设置如下:
ResourceConfig rc = new ResourceConfig()
.packages(true,
"com.mystuff"
)
.property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true");
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(base_uri), rc);
ApplicationHandler handler = new ApplicationHandler(rc);
ServiceLocatorUtilities.enableImmediateScope(handler.getServiceLocator());
任何指导将不胜感激!干杯,菲尔