使用apache felix白板(OSGi)构建servlet的问题

时间:2013-12-08 23:42:51

标签: servlets osgi apache-felix whiteboard bndtools

我正在尝试使用BndTools构建一个servlet。 我遵循了本教程:http://www.ralfebert.de/archive/java/osgi_server/

但是..我无法让servlet工作:(。 问题是apache felix whiteboard bundle给出了调试消息: 忽略Servlet服务[javax.servlet.Servlet],别名缺失或为空

我用Google搜索了几个小时,但我无法得到任何问题的答案。 当我尝试访问localhost:8080时,我收到以下消息:

访问/的问题。原因是:

NOT_FOUND

这是我的servlet的代码:

package com.example.helloworld;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.*;

import aQute.bnd.annotation.component.Component;

@Component(provide=Servlet.class, properties = { "alias=/" })
public class HelloWorldServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.getWriter().append("Hello World!");
    }

}

我错过了什么或者我做错了什么?

这是我的bnd.bnd文件的来源:

-buildpath: osgi.core,\
    osgi.cmpn,\
    biz.aQute.bnd.annotation,\
    junit.osgi,\
    org.apache.felix.http.jetty
-sub: *.bnd
-runfw: org.apache.felix.framework;version='[4.0.3,4.0.3]'

因为我使用的是更高版本的BndTools,我无法管理.bnd文件中的所有内容。所以这里是我的run.runbnd文件的来源:

-runfw: org.apache.felix.framework;version='[4,5)'
-runee: JavaSE-1.6
-runsystemcapabilities: ${native_capability}

-resolve.effective: active



-runrequires: osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.runtime)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.http.jetty)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.webconsole)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.http.whiteboard)'
-runbundles: org.apache.felix.gogo.command,\
    org.apache.felix.gogo.runtime,\
    org.apache.felix.gogo.shell,\
    osgi.cmpn,\
    org.apache.felix.http.jetty,\
    org.apache.felix.http.whiteboard,\
    com.example.helloworld.org.example;version=latest

1 个答案:

答案 0 :(得分:1)

您需要将提供声明性服务的服务组件运行时的bundle添加到运行配置中。该bundle名为org.apache.felix.scr,可以在存储库视图的Bndtools Hub存储库中找到。

您完美地配置了组件,但是您需要一个SCR包来在运行时实际处理配置。