-
Notifications
You must be signed in to change notification settings - Fork 327
Description
Using epublib-core in a springboot application causes two issues:
- a warning: Class Path Contains Multiple SLF4J Bindings -- this can be ignored
- IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
The problem seems to me, the slf4j-simple binding (provider) inherited from the parent pom.
Considering the core library intention as a client, it might be better served by just using the sl4j-api and omitting the binding (provider). From baeldung:
It is worth noting that embedded components such as libraries or frameworks should never declare a dependency on any SLF4J binding. This is because when a library declares a compile-time dependency on an SLF4J binding, it imposes that binding on the end-user. Obviously, this negates SLF4J's basic purpose. Consequently, they should only depend on the slf4j-api library.
A commonly proposed solution is to add to your gradle build file:
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'ch.qos.logback', module: 'logback-classic'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
However, this disables logging configuration for the entire app.
On the other hand, this doesn't seem to work:
compile ('nl.siegmann.epublib:epublib-core:4.0') {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
The solution that worked for me was to:
- remove the sl4j-simple dependency from the parent pom and the epublib-core pom files
- build the jar again and use it.
Now it no longer has a conflict and spring boot logging will work as expected.