我正在将我的log4j配置从PatternLayout切换到JasonLayout。更改后,我开始遇到以下错误:
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
这个类来自jackson-databind,在我的例子中,它是2.13.1版本,它来自log4j 2.17.2的依赖项。我使用gradle来管理依赖项,log4j依赖项来自一个内部框架,在该框架中,我看到log4j加载为:
implementation('org.apache.logging.log4j:log4j-api')
runtimeOnly('org.apache.logging.log4j:log4j-core')
runtimeOnly('org.apache.logging.log4j:log4j-jcl')
会不会是我将log4j-core和logj 4-jcl作为runtimeOnly加载的事实导致了这个问题?
1条答案
按热度按时间9udxz4iz1#
jackson-databind
是log4j-core
的一个可选依赖项。基本上,这意味着如果你想包含它,你必须在你的项目上显式地声明它为依赖项(参见Maven optional dependencies)。