我正在尝试(学习如何)javax.servlet.Servlet使用 OSGi 提供的声明性服务(DS)创建一个 Servlet(),如下所示:import java.io.IOException;import javax.servlet.Servlet;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.osgi.service.component.annotations.Component;@Component(service = Servlet.class, property = { "alias:String=/hello" }, immediate = true)public class LogsHTTPServlet extends HttpServlet { private static final long serialVersionUID = 2302372200114479484L; @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { resp.setContentType("text/plain"); resp.getWriter().println("It works!"); } catch (Exception e) { e.printStackTrace(); } resp.setStatus(200); }}当我在Eclipse (2019-03 (4.11.0), build id: 20190314-1200)上使用自定义运行配置在此目标平台上运行项目时,我使用此 VM 参数设置(和其他必需的依赖项)(),我在 osgi 控制台中看到如下内容: org.eclipse.jetty.server-Dorg.osgi.service.http.port=8080osgi> 2019-05-07 18:22:28.236:INFO::Start Level: Equinox Container: 0d7d3d67-401b-48eb-b016-6e6c0c16352c: Logging initialized @1590ms to org.eclipse.jetty.util.log.StdErrLog2019-05-07 18:22:28.388:INFO:oejs.session:Start Level: Equinox Container: 0d7d3d67-401b-48eb-b016-6e6c0c16352c: DefaultSessionIdManager workerName=node02019-05-07 18:22:28.388:INFO:oejs.session:Start Level: Equinox Container: 0d7d3d67-401b-48eb-b016-6e6c0c16352c: No SessionScavenger set, using defaults2019-05-07 18:22:28.389:INFO:oejs.session:Start Level: Equinox Container: 0d7d3d67-401b-48eb-b016-6e6c0c16352c: node0 Scavenging every 660000ms2019-05-07 18:22:28.427:INFO:oejs.session:Start Level: Equinox Container: 0d7d3d67-401b-48eb-b016-6e6c0c16352c: node0 Scavenging every 660000ms我该如何解决这个问题?
1 回答
森栏
TA贡献1810条经验 获得超5个赞
而不是alias
使用该osgi.http.whiteboard.servlet.pattern
属性:
@Component(service = Servlet.class, property = {"osgi.http.whiteboard.servlet.pattern=/hello/*" })
或者,使用当前的 osgi 纲要依赖项(版本 7.0.0),您可以使用如下@org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern
注释:
@Component(service=Servlet.class) @org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern("/hello/*")
添加回答
举报
0/150
提交
取消