1

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!

NikosDim
  • 1,398
  • 2
  • 21
  • 40

2 Answers2

4

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
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thanks Christian for your answer. I ll test it tonight. Is it possible to install the scr feature on Karaf container from my feature.xml file instead of doing it manually in the Karaf container terminal? – NikosDim May 20 '19 at 14:25
  • 1
    Yes. You can add it as a feature dependency to the feature file. – Christian Schneider May 21 '19 at 06:14
  • It perfectly worked. I have changed my repo and the error is gone and my app starts successfully but the Service (@Component) seems that it is not working. I did edit the properties using the config:property-set command then I did config:update to save it but the method with the Modified annotation was never invoked (I have some print statements into my Modified annotated method but I never see it). Is there anything wrong with my configuration? – NikosDim May 21 '19 at 18:16
  • Answering my previous comment. I was missing the immediate=true in the Component annotation – NikosDim May 21 '19 at 18:17
2

You are getting the mentioned error because of either the dependent bundle is not installed or the installed bundle's version is not in the range,

You can check whether the bundle is installed or not and what is the installed version by below command in the karaf terminal:

  la -l|grep "#bundle name"

where bundle name is the bundle for which you are getting the error,

Sometimes it might be possible that only one bundle is missing but there is a possibility that the feature is not installed, the feature is nothing but a group of bundles,

To check whether the feature is installed or not, use below command :

feature:list|grep "#feature name" 

Here, you can install the feature and it should resolve the issue

feature:install scr