0

In what scenario, the following error could happen? This happens sporadically when starting an application with several bundles. What would be the fix for this error?

Caused by: org.osgi.framework.BundleException: Unable to resolve module com.springsource.slf4j.api [135.0] because it exports package 'org.slf4j.spi' and is also exposed to it from com.springsource.slf4j.api [135.0] via the following dependency chain:

  com.springsource.slf4j.api [135.0]
    import: (&(package=org.slf4j.impl)(version>=1.6.1)(!(version>=2.0.0)))
     |
    export: package=org.slf4j.impl; uses:=org.slf4j
  com.springsource.slf4j.api [135.0]
    import: (&(package=org.slf4j)(version>=1.6.1)(version<=1.6.1))
     |
    export: package=org.slf4j; uses:=org.slf4j.spi
  com.springsource.slf4j.api [135.0]
    import: (&(package=org.slf4j.spi)(version>=1.6.1)(version<=1.6.1))
     |
    export: package=org.slf4j.spi
  com.springsource.slf4j.api [135.0]
    at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3574)
    at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1619)
Gopal
  • 1,372
  • 2
  • 16
  • 32

1 Answers1

1

SLF4J is OSGi friendly since a while so there is no need to use springsource based jar-s.

Install the newest slf4j-api jar with the implementation you would like to use!

How it works:

slf4j-api uses classes that are not in the jar and they are not imported. slf4j-xxximpl (like slf4j-simple) are fragment bundles where the host is slf4j-api so they will have a common classloader.

This means that you have to install an slf4j-api and slf4j-xxx together (if you install it runtime call a refresh on the container if necessary to have good wirings). This also means that slf4j cannot work with more implementations and it is also not a good idea to have multiple versions of slf4j-api in the same container.

Solution: Remove the springsource based jar and install the newest slf4j-api and impl jars into the container and after that call refresh if necessary.

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31