Home > database >  java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider

Time:09-20

I'm switching my log4j config from PatternLayout to JasonLayout. After the change, I started having the following error:

ERROR Could not create plugin of type class org.apache.logging.log4j.core.layout.JsonLayout for element JsonLayout: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider
    at org.apache.logging.log4j.core.layout.JsonLayout.<init>(JsonLayout.java:159)
    at org.apache.logging.log4j.core.layout.JsonLayout.<init>(JsonLayout.java:71)
    at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:103)
    at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:79)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
    at de.ic_consult.planetarium.listener.ListenerEmbedded.<clinit>(ListenerEmbedded.java:49)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ser.FilterProvider
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 21 more

This class comes from jackson-databind, which in my case, is version 2.13.1, that comes as dependency from log4j 2.17.2. I'm using gradle to manage the dependencies, and the log4j dependency comes from an internal framework, in which I saw that log4j is loaded as:

  implementation('org.apache.logging.log4j:log4j-api')
  runtimeOnly('org.apache.logging.log4j:log4j-core')
  runtimeOnly('org.apache.logging.log4j:log4j-jcl')

Could it be that the fact that I'm loading log4j-core and logj4-jcl as runtimeOnly is causing this problem?

CodePudding user response:

jackson-databind is an optional dependency of log4j-core. Basically it means that if you want to include it, you'll have to declare it explicitly as dependency on your project (cf. Maven optional dependencies).

  • Related