由于命名空间与“jakstash”/“javax”冲突,无法在Sping Boot 3.0中运行logstash

6pp0gazn  于 12个月前  发布在  Logstash
关注(0)|答案(1)|浏览(236)

我们正在升级到Sping Boot 3.x的过程中,在运行时我们遇到了这个异常:“class not found exception”for:javax.xml.bind.annotation.XmlElement

java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
    at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:137)
    at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:124)
    at com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.setupModule(JaxbAnnotationModule.java:98)
    at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:879)
    at com.fasterxml.jackson.databind.ObjectMapper.registerModules(ObjectMapper.java:1081)
    at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1165)
    at net.logstash.logback.composite.AbstractCompositeJsonFormatter.createJsonFactory(AbstractCompositeJsonFormatter.java:247)
    at net.logstash.logback.composite.AbstractCompositeJsonFormatter.start(AbstractCompositeJsonFormatter.java:117)
    at net.logstash.logback.LogstashFormatter.start(LogstashFormatter.java:144)
    at net.logstash.logback.encoder.CompositeJsonEncoder.start(CompositeJsonEncoder.java:129)

字符串
仔细观察,这似乎是由logstash引起的,这是一个与ElasticSearch一起使用的日志框架。
logstash的当前版本是6.4.x,所以我们将其提升到7.4.x(使用Gradle:implementation(“net.logstash.logback:logstash-logback-encoder:7.4”)),但我们仍然遇到了同样的问题。
原因是有一个间接使用XML绑定的依赖(https://mvnrepository.com/artifact/net.logstash.logback/logstash-logback-encoder/7.4)问题是有一个使用XML绑定的logback依赖(称为logback-classic)。在研究了一下并访问了这个网站:https://logback.qos.ch/news.html后,我们意识到有两个版本的logback classic使用不同的命名空间。

logback-classic 1.3.x -> uses javax namespace 
logback-classic 1.4.x -> uses jakarta namespace


我的理解是,我们需要将logback-classic更新为1.4,因为该版本使用与SpringBoot 3.x xml绑定兼容的jakebooknamespace。
因此,我们在gradle构建中显式地将logback-classic设置为1.4,如下所示:

implementation("ch.qos.logback:logback-classic:1.4.14")
implementation("net.logstash.logback:logstash-logback-encoder:7.4")


但是,当我们运行它时,我们得到一个不同的错误:

Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.ClassLoader ch.qos.logback.core.util.Loader.systemClassloaderIfNull(java.lang.ClassLoader)'
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:73)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:66)
    at ch.qos.logback.classic.spi.LogbackServiceProvider.initializeLoggerContext(LogbackServiceProvider.java:52)
    at ch.qos.logback.classic.spi.LogbackServiceProvider.initialize(LogbackServiceProvider.java:41)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:183)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:170)
    at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:455)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:441)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:390)

vngu2lb8

vngu2lb81#

对我来说,似乎有一个版本差异。我发现这在logstash-logback-encoder README的官方文档。
https://github.com/logfellow/logstash-logback-encoder

If you get ClassNotFoundException/NoClassDefFoundError/NoSuchMethodError at runtime, then ensure the required dependencies (and appropriate versions) as specified in the pom file from the maven repository exist on the runtime classpath. Specifically, the following need to be available on the runtime classpath:

jackson-databind / jackson-core / jackson-annotations >= 2.12.0
logback-core >= 1.3.0
logback-classic >= 1.3.0 (required for logging LoggingEvents)
logback-access >= 1.3.0 (required for logging AccessEvents)
slf4j-api (usually comes as a transitive dependency of logback-classic)
java-uuid-generator (required if the uuid provider is used)

字符串

相关问题