首页 > 解决方案 > Karaf OSGi 配置抛出 ResolutionException: Unable to resolve root: missing requirements [root] osgi.identity;

问题描述

我正在创建一个将在 Karaf 上运行的 Spring Boot 应用程序。我试图在 Karaf 中公开项目配置属性,以便能够使用 config:property-set 更改属性,而无需重新部署应用程序。

因此,我设法配置了我的 karaf 功能以将属性公开给 Karaf,但我正在尝试创建一个 OSGi 组件,以便能够在使用 config:property-set 更改属性时获取更新。

尝试安装 .kar 文件时遇到的错误如下:

[[A2019-05-19T23:09:32,926 | INFO  | pipe-kar:install file:/Users/nikos/development/interlink/thirdParty/osgi-karaf-spring-boot-demo/osgi-spring-boot-demo-features/target/osgi-spring-boot-demo-features-0.0.1-SNAPSHOT.kar | KarServiceImpl                   | 35 - org.apache.karaf.kar.core - 4.1.3 | Added feature repository 'mvn:com.nemesis/osgi-spring-boot-demo-features/0.0.1-SNAPSHOT/xml/features'
2019-05-19T23:09:32,927 | INFO  | pipe-kar:install file:/Users/nikos/development/interlink/thirdParty/osgi-karaf-spring-boot-demo/osgi-spring-boot-demo-features/target/osgi-spring-boot-demo-features-0.0.1-SNAPSHOT.kar | FeaturesServiceImpl              | 9 - org.apache.karaf.features.core - 4.1.3 | Adding features: osgi-spring-boot-demo-feature/[0.0.1.SNAPSHOT,0.0.1.SNAPSHOT]
2019-05-19T23:09:32,995 | WARN  | pipe-kar:install file:/Users/nikos/development/interlink/thirdParty/osgi-karaf-spring-boot-demo/osgi-spring-boot-demo-features/target/osgi-spring-boot-demo-features-0.0.1-SNAPSHOT.kar | KarServiceImpl                   | 35 - org.apache.karaf.kar.core - 4.1.3 | Unable to install Kar feature osgi-spring-boot-demo-feature/0.0.1.SNAPSHOT
org.osgi.service.resolver.ResolutionException: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=osgi-spring-boot-demo-feature; type=karaf.feature; version="[0.0.1.SNAPSHOT,0.0.1.SNAPSHOT]"; filter:="(&(osgi.identity=osgi-spring-boot-demo-feature)(type=karaf.feature)(version>=0.0.1.SNAPSHOT)(version<=0.0.1.SNAPSHOT))" [caused by: Unable to resolve osgi-spring-boot-demo-feature/0.0.1.SNAPSHOT: missing requirement [osgi-spring-boot-demo-feature/0.0.1.SNAPSHOT] osgi.identity; osgi.identity=com.nemesis.osgi-spring-boot-demo-bundle; type=osgi.bundle; version="[0.0.1.SNAPSHOT,0.0.1.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve com.nemesis.osgi-spring-boot-demo-bundle/0.0.1.SNAPSHOT: missing requirement [com.nemesis.osgi-spring-boot-demo-bundle/0.0.1.SNAPSHOT] osgi.extender; filter:="(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))"]]
    at org.apache.felix.resolver.ResolutionError.toException(ResolutionError.java:42) ~[?:?]
    at org.apache.felix.resolver.ResolverImpl.doResolve(ResolverImpl.java:391) ~[?:?]
    at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:377) ~[?:?]
    at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:349) ~[?:?]
    at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:218) ~[?:?]
    at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:291) ~[?:?]
    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1248) ~[?:?]
    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$1(FeaturesServiceImpl.java:1147) ~[?:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]

这是我的github 仓库。我正在使用 java 8 和 maven 3.6、org.osgi.core 5.0.0、Karaf 4.1.3

有什么想法可以解决这个问题吗?使用@Component 和@Modified 从 Karaf 获取属性修改更新的正确方法是什么?

提前致谢!

标签: javaosgiapache-karafosgi-bundlekaraf-maven-plugin

解决方案


错误消息意味着您缺少提供捆绑包要求之一的捆绑包。

您会在此长错误消息的末尾找到缺少的要求:

(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))

这意味着您缺少 osgi.component 模型的扩展器。

那么那里发生了什么?您在类中使用声明性服务注释。maven bundle 插件读取它们并为声明性服务创建 xml 以及对上述扩展器的要求。

因此,此要求可帮助您在安装捆绑软件时不会错过声明性服务运行时。

在 karaf 的情况下,解决方案是安装一个提供运行时的功能:

feature:install scr

推荐阅读