如何创建Restful服务并部署OSGi容器?

Li'*_*Li' 6 java eclipse rest osgi maven

我的目标是使用Eclipse创建Restful服务Maven项目.然后将其打包为捆绑包并将其部署到Fuse ESB karaf OSGi容器中.到目前为止,我所知道的是如何使用JAX-RS API注释,@ Path @GET:

package com.restfultest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/example")
public class ExampleService {

@GET
public String sayHello() {
    return "Hello Restful service";
 }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:1.我应该使用什么样的maven原型?maven-archetype-webapp还是快速入门?

2.如何实施Activator?像这样?

public class Activator implements BundleActivator {

private ServiceRegistration<?> registration;

public void start(BundleContext context) throws Exception {
    // TODO Auto-generated method stub
    ExampleService exampleService = new ExampleService();
    registration = context.registerService( ExampleService.class.getName(), exampleService, null );
}

public void stop(BundleContext context) throws Exception {
    // TODO Auto-generated method stub
    registration.unregister();
}

}
Run Code Online (Sandbox Code Playgroud)

3.如何注册和发布服务(如何配置端点地址和端口)?

我是osgi的新手.有没有人可以提供一些资源或详细的教程?

ili*_*ans 0

  1. 您需要创建一个 OSGI 包。有一些创建 Maven 项目的原型:

  2. 您的激活器看起来正确。

  3. 这个问题我无法回答,但看起来这个项目满足了您的需要: https: //github.com/hstaudacher/osgi-jax-rs-connector

一般来说,我建议您自己阅读OSGI 规范,这是一本很好的读物,并且解释了很多事情。