[英]How to inject object with HK2 in main method in a embedded Grizzly Jersey application
[英]How to get the HTTP request method on a Grizzly-embedded Jersey application?
我正在研究JAX-RS應用程序。 以前,我將它作為WAR掛載在Tomcat服務器上,並使用以下方法獲取HTTTP請求方法: javax.servlet.http.HttpServletRequest.getMethod()
。
但是,現在我在應用程序上使用嵌入式Grizzly服務器,並且在啟動時發現以下錯誤:
Missing dependency for constructor public wci.api.resource.AudioSessionResource(javax.servlet.http.HttpServletRequest) at parameter index 0
我所有的資源都擴展了MyHappyCustomResource
類,該類具有一個構造函數,該構造函數接收HttpServletRequest
,它由資源構造函數通過注入提供。
這是資源構造函數的示例, super
調用來自MyHappyCustomResource
:
import javax.servlet.http.HttpServletRequest;
public AudioSessionResource(@Context HttpServletRequest request) {
super(request);
this.dao = new AudioSessionDao(this.sessionManager.getCurrentSession());
}
現在,我只需要這個就可以獲取HTTP方法,因此,我們歡迎其他任何或更正確的方法來使用它。
解決方案是使用Grizzly官方網站上此頁面所述的Grizzly的Request類:
https://grizzly.java.net/httpserverframework.html
與Servlet規范提供的抽象類似:HttpHandler(Servlet),Request(HttpServletRequest),Response(HttpServletResponse)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.