How to use servlet with OSGi

前端 未结 6 1343
悲&欢浪女
悲&欢浪女 2021-01-11 19:31

I want to create and deploy a web service to OSGi container. For example, publish the service to the address:

http://localhost:8080/testservice. 

6条回答
  •  逝去的感伤
    2021-01-11 19:50

    I would like to follow up on the answer of Peter Kriens. With @Component annotations available in the OSGi specification, the example could look like this:

    @Component(service = Servlet.class, property = { "osgi.http.whiteboard.servlet.pattern = /hello" })
    public class HelloWorldServlet extends HttpServlet { ... }
    

    The @Component annotation is imported from org.osgi.service.component and the property that specifies the implemented service has changed its name to service.

    Despite its name, property can hold multiple properties for example

    @Component(service = ..., property = { "a=b", "c=d" })
    

    or you could use properties to specify one or more properties files like so:

    @Component(service = ..., properties = { "OSGI-INF/servlet.properties" } )
    

    The above has been tested with the HttpService that comes with Apache Felix. The documentation of the Apache Felix HTTP Service can be found here: http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html

提交回复
热议问题