gpt4 book ai didi

java - OSGi REST 服务不工作(bnd 工具)

转载 作者:行者123 更新时间:2023-12-01 18:28:17 27 4
gpt4 key购买 nike

我正在根据Amdatu指南编写一个REST服务,它非常简单,但它向我抛出一个错误,我已经添加了所有依赖项,但仍然遇到缺少需求错误

这是一条错误消息

! could not resolve the bundles
! Failed to start bundle org.apache.felix.http.whiteboard-2.3.0, exception Unresolved constraint in bundle org.apache.felix.http.whiteboard [13]: Unable to resolve 13.0: missing requirement [13.0] osgi.wiring.package; (&(osgi.wiring.package=javax.servlet)(version>=3.0.0)(!(version>=4.0.0)))
! Failed to start bundle org.amdatu.web.rest.wink-1.0.8, exception Unresolved constraint in bundle org.amdatu.web.rest.wink [14]: Unable to resolve 14.0: missing requirement [14.0] osgi.wiring.package; (&(osgi.wiring.package=org.codehaus.jackson.jaxrs)(version>=1.9.0)(!(version>=2.0.0)))
! Failed to start bundle org.apache.felix.http.jetty-2.3.0, exception Unresolved constraint in bundle org.apache.felix.http.jetty [15]: Unable to resolve 15.0: missing requirement [15.0] osgi.wiring.package; (&(osgi.wiring.package=javax.servlet)(version>=3.0.0)(!(version>=4.0.0)))
____________________________
Welcome to Apache Felix Gogo

g!

这里是实现

package web.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("hellorest")
public class HelloWorldResource {
@GET
@Produces(MediaType.TEXT_HTML)
public String say_hello() {
return "hello";
}

}

这是一个 Activator 类

package web.rest;

import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;

public class Activator extends DependencyActivatorBase{

@Override
public void destroy(BundleContext arg0, DependencyManager arg1)
throws Exception {
// TODO Auto-generated method stub

}

@Override
public void init(BundleContext arg0, DependencyManager manager)
throws Exception {
manager.add(createComponent()
.setInterface(Object.class.getName(),null)
.setImplementation(HelloWorldResource.class));
}

}

我添加了这些来构建依赖项 enter image description here

这些是运行依赖项 enter image description here

如果你让我把Servlet包改成3.0,我会回答一些其他服务要求Servlet版本必须低于3.0,现在我无法同时满足它们。

最佳答案

问题出在您的“运行 bundle ”配置中:

  1. javax.servlet 包替换为 org.apache.felix.http.servlet-api。它包含适当版本​​的 javax.servlet 包。
  2. 同时添加 jackson-jaxrs bundle

这两个 bundle 也可在“Amdatu 依赖项”存储库中找到。

关于java - OSGi REST 服务不工作(bnd 工具),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com