spring-mvcosgiwebsphere-libertyblueprint-osgieclipse-virgo

Gemini Blueprint - PackageAdmin service reference is returning null with spring mvc in IBM Liberty


I am trying to deploy the spring osgi application in IBM Websphere liberty server using gemini blueprint virgo DM. While deploying the application, I am facing the below error, says " ....PackageAdmin service is required . Can anyone has an idea on this?

java.lang.IllegalStateException: org.osgi.service.packageadmin.PackageAdmin service is required at org.eclipse.gemini.blueprint.io.internal.resolver.PackageAdminResolver$1.run(PackageAdminResolver.java:179) at org.eclipse.gemini.blueprint.io.internal.resolver.PackageAdminResolver$1.run(PackageAdminResolver.java:174) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.gemini.blueprint.io.internal.resolver.PackageAdminResolver.getPackageAdmin(PackageAdminResolver.java:174) at org.eclipse.gemini.blueprint.io.internal.resolver.PackageAdminResolver.getImportedBundles(PackageAdminResolver.java:67) at org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.findClassPathMatchingResources(OsgiBundleResourcePatternResolver.java:217) at org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.findResources(OsgiBundleResourcePatternResolver.java:154) at org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.getResources(OsgiBundleResourcePatternResolver.java:186) at org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext.getResources(AbstractOsgiBundleApplicationContext.java:439) at org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext.getResources(ServerOsgiBundleXmlWebApplicationContext.java:346) at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:270) at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:248) at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:87) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) ... 25 more


Solution

  • Starting from fixpack 8.5.5.9 of Liberty, PackageAdmin will not be available to the application region unless you create a custom Liberty feature that exports the package admin service using the IBM-API-Service header.

    1. Create a Liberty feature as explained in this article

    2. Make sure that the feature exports PackageAdmin as in the example below

    3. Declare your custom feature to server.xml using usr:myfeature

      Subsystem-ManifestVersion: 1.0
      IBM-Feature-Version: 2
      IBM-ShortName: myfeature
      Subsystem-SymbolicName: myfeature;visibility:=public 
      Subsystem-Version: 1.0.0
      Subsystem-Type: osgi.subsystem.feature
      Manifest-Version: 1.0
      IBM-API-Service: javax.xml.parsers.SAXParserFactory,
       org.osgi.service.packageadmin.PackageAdmin,
       org.osgi.service.cm.ConfigurationAdmin
      

    According to the description of a defect fix in 8.5.5.9 fixpack, IBM made this change because Liberty was leaking its own services to the application, so now the OSGi services registered by Liberty are not visible to the application unless you create a feature like the one below to export explicitly those that you need.