未解决的要求:osgi.component
Unresolved requirement: osgi.component
我正在尝试在 Karaf 上开发一个包含 REST API 和来自定制服务的调用的 OSGi WAB。然而,由于一些奇怪的原因,OSGi 框架抱怨一个不满意的能力,osgi.component
。
我想知道:
- 我该如何解决这个问题?
- 什么是
osgi.component
捆绑包?为什么需要?
- 为什么 maven-bundle-plugin(因此也是 bnd)在条目 "Require-Capability" 中声明它?
- 如果我需要在OSGi框架上安装它,我在哪里可以找到它?
一些附加信息:
- 卡拉夫版本:4.0.7;
- maven 捆绑插件:3.2.0;
- OS: Windows 10 64 位;
- IDE:日食霓虹灯;
一些提供额外信息的代码:
整个错误:
Error executing command: Error executing command on bundles:
Error starting bundle 96: Unable to resolve com.massimobono.karaf.examples.user-fully-rest [96](R 96.0): missing
requirement [com.massimobono.karaf.examples.user-fully-rest [96](R
96.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))
Unresolved requirements:
[[com.massimobono.karaf.examples.user-fully-rest [96](R 96.0)]
osgi.extender;
(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))]
清单文件:
Manifest-Version: 1.0
Bundle-SymbolicName: com.massimobono.karaf.examples.user-fully-rest
Archiver-Version: Plexus Archiver
Built-By: massi
Bnd-LastModified: 1479908575162
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Import-Package: com.massimobono.karaf.examples.user;version="[0.0,1)",
com.massimobono.karaf.examples.user.service;version="[0.0,1)",javax.w
s.rs;version="[2.0,3)",javax.ws.rs.core;version="[2.0,3)"
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.compo
nent)(version>=1.3.0)(!(version>=2.0.0)))",osgi.service;filter:="(obj
ectClass=com.massimobono.karaf.examples.user.service.UserService)";ef
fective:=active,osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Service-Component: OSGI-INF/com.massimobono.karaf.examples.user.ui.ful
lyrest.UserRest.xml
Tool: Bnd-3.2.0.201605172007
Originally-Created-By: Maven Integration for Eclipse
Export-Package: com.massimobono.karaf.examples.user.ui.fullyrest;uses:
="javax.ws.rs,javax.ws.rs.core";version="0.0.1"
Bundle-Name: user-fully-rest Maven Webapp
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_91
休息基地class:
package com.massimobono.karaf.examples.user.ui.fullyrest;
import java.time.LocalDateTime;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.massimobono.karaf.examples.user.User;
import com.massimobono.karaf.examples.user.service.UserService;
import com.massimobono.karaf.examples.user.service.UserServiceException;
@Path("user")
@Component(immediate=true)
public class UserRest {
@Reference
private volatile UserService userService;
@GET
@Produces(MediaType.TEXT_HTML)
public String getUserNumber() {
try {
return String.format("<h1>Total users: %d</h1>", this.userService.size());
} catch (UserServiceException e) {
return String.format("Couldn't fetch total users because %s", e.getMessage());
}
}
@PUT
@Path("add/{name}/{surname}")
@Produces(MediaType.TEXT_HTML)
public String add(@PathParam("name") String name, @PathParam("surname") String surname) {
try {
User u = new User(name, surname, LocalDateTime.now());
this.userService.addUser(u);
return String.format("<h1>New user with id %d</h1>", u.getId());
} catch (UserServiceException e) {
return String.format("<h1>Couldn't fethc total users because %s</h1>", e.getMessage());
}
}
@DELETE
@Path("remove/{id}")
@Produces(MediaType.TEXT_HTML)
public String remove(@PathParam("id") int id) {
User u;
try {
u = this.userService.getUser(id);
this.userService.removeUser(u);
return String.format("<h1>User name=%s surname=%s removed correctly</h1>", u.getName(), u.getSurname());
} catch (UserServiceException e) {
return String.format("<h1>Couldn't remove user because %s</h1>", e.getMessage());
}
}
}
感谢您的回复
How can I solve this issue?
您的 Karaf 运行时很可能缺少 SCR。您可以使用 feature:install scr
安装它
What is osgi.component bundle? Why is needed?
这不是捆绑包,而是要求。基本上它说你的 bundle 需要 SCR(或其他东西)知道如何通过声明服务处理和注册其中定义的组件。
Why maven-bundle-plugin (thereby also bnd), declares it inside the entry "Require-Capability"?
因为它看到您正在使用声明式服务并且知道它们将无法工作,除非您在运行时有一些东西可以理解它们是如何声明的并且知道如何管理它们的生命周期。如果不存在需求(我相信 bnd 的早期版本就是这种情况),那么您的捆绑包将毫无问题地启动,但服务仍将未注册/激活。
If I need to install it on the OSGi framework, where may I find it?
在 Karaf 中,它作为功能提供(请参阅第一个问题的答案)。在普通 OSGi 运行时(Felix、Equinox 等)中,您需要手动安装它。 It's available in Maven central.
我正在尝试在 Karaf 上开发一个包含 REST API 和来自定制服务的调用的 OSGi WAB。然而,由于一些奇怪的原因,OSGi 框架抱怨一个不满意的能力,osgi.component
。
我想知道:
- 我该如何解决这个问题?
- 什么是
osgi.component
捆绑包?为什么需要? - 为什么 maven-bundle-plugin(因此也是 bnd)在条目 "Require-Capability" 中声明它?
- 如果我需要在OSGi框架上安装它,我在哪里可以找到它?
一些附加信息:
- 卡拉夫版本:4.0.7;
- maven 捆绑插件:3.2.0;
- OS: Windows 10 64 位;
- IDE:日食霓虹灯;
一些提供额外信息的代码:
整个错误:
Error executing command: Error executing command on bundles: Error starting bundle 96: Unable to resolve com.massimobono.karaf.examples.user-fully-rest [96](R 96.0): missing requirement [com.massimobono.karaf.examples.user-fully-rest [96](R 96.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0))) Unresolved requirements: [[com.massimobono.karaf.examples.user-fully-rest [96](R 96.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))]
清单文件:
Manifest-Version: 1.0
Bundle-SymbolicName: com.massimobono.karaf.examples.user-fully-rest
Archiver-Version: Plexus Archiver
Built-By: massi
Bnd-LastModified: 1479908575162
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Import-Package: com.massimobono.karaf.examples.user;version="[0.0,1)",
com.massimobono.karaf.examples.user.service;version="[0.0,1)",javax.w
s.rs;version="[2.0,3)",javax.ws.rs.core;version="[2.0,3)"
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.compo
nent)(version>=1.3.0)(!(version>=2.0.0)))",osgi.service;filter:="(obj
ectClass=com.massimobono.karaf.examples.user.service.UserService)";ef
fective:=active,osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Service-Component: OSGI-INF/com.massimobono.karaf.examples.user.ui.ful
lyrest.UserRest.xml
Tool: Bnd-3.2.0.201605172007
Originally-Created-By: Maven Integration for Eclipse
Export-Package: com.massimobono.karaf.examples.user.ui.fullyrest;uses:
="javax.ws.rs,javax.ws.rs.core";version="0.0.1"
Bundle-Name: user-fully-rest Maven Webapp
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_91
休息基地class:
package com.massimobono.karaf.examples.user.ui.fullyrest;
import java.time.LocalDateTime;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.massimobono.karaf.examples.user.User;
import com.massimobono.karaf.examples.user.service.UserService;
import com.massimobono.karaf.examples.user.service.UserServiceException;
@Path("user")
@Component(immediate=true)
public class UserRest {
@Reference
private volatile UserService userService;
@GET
@Produces(MediaType.TEXT_HTML)
public String getUserNumber() {
try {
return String.format("<h1>Total users: %d</h1>", this.userService.size());
} catch (UserServiceException e) {
return String.format("Couldn't fetch total users because %s", e.getMessage());
}
}
@PUT
@Path("add/{name}/{surname}")
@Produces(MediaType.TEXT_HTML)
public String add(@PathParam("name") String name, @PathParam("surname") String surname) {
try {
User u = new User(name, surname, LocalDateTime.now());
this.userService.addUser(u);
return String.format("<h1>New user with id %d</h1>", u.getId());
} catch (UserServiceException e) {
return String.format("<h1>Couldn't fethc total users because %s</h1>", e.getMessage());
}
}
@DELETE
@Path("remove/{id}")
@Produces(MediaType.TEXT_HTML)
public String remove(@PathParam("id") int id) {
User u;
try {
u = this.userService.getUser(id);
this.userService.removeUser(u);
return String.format("<h1>User name=%s surname=%s removed correctly</h1>", u.getName(), u.getSurname());
} catch (UserServiceException e) {
return String.format("<h1>Couldn't remove user because %s</h1>", e.getMessage());
}
}
}
感谢您的回复
How can I solve this issue?
您的 Karaf 运行时很可能缺少 SCR。您可以使用 feature:install scr
What is osgi.component bundle? Why is needed?
这不是捆绑包,而是要求。基本上它说你的 bundle 需要 SCR(或其他东西)知道如何通过声明服务处理和注册其中定义的组件。
Why maven-bundle-plugin (thereby also bnd), declares it inside the entry "Require-Capability"?
因为它看到您正在使用声明式服务并且知道它们将无法工作,除非您在运行时有一些东西可以理解它们是如何声明的并且知道如何管理它们的生命周期。如果不存在需求(我相信 bnd 的早期版本就是这种情况),那么您的捆绑包将毫无问题地启动,但服务仍将未注册/激活。
If I need to install it on the OSGi framework, where may I find it?
在 Karaf 中,它作为功能提供(请参阅第一个问题的答案)。在普通 OSGi 运行时(Felix、Equinox 等)中,您需要手动安装它。 It's available in Maven central.