Search code examples
javaosgiapache-karafosgi-bundlekaraf-maven-plugin

Karaf OSGi config throws ResolutionException: Unable to resolve root: missing requirement [root] osgi.identity;


I am creating a Spring Boot app that will run on Karaf. I am trying to expose the project configuration properties in Karaf in order to be able to change the properties using config:property-set without the need to redeploy the app.

So I have managed to configure my karaf feature to expose the properties to Karaf but I am trying to create a OSGi Component to be able to get updates when a property is changes with config:property-set.

The error I am getting when trying to install my .kar file is the following:

[[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) [?:?]

Here is my github repo. I am using java 8 with maven 3.6, org.osgi.core 5.0.0, Karaf 4.1.3

Any ideas how can I resolve the issue? Is the the correct way of getting property modification updates from Karaf by using @Component and @Modified?

Thanks in advance!


Solution

  • The error message means you are missing a bundle that provides one of the requirements of your bundle.

    You find the missing requirement at the end of this long error message:

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

    This means you are missing an extender for the osgi.component model.

    So what is going on there? You use the declarative services annotations in your classes. The maven bundle plugin reads them and creates xml for the declarative services as well as a requirement for the extender above.

    So this requirement helps you to not miss the declarative services runtime when you install your bundle.

    In case of karaf the solution is to install a feature that provides the runtime:

    feature:install scr