web-dev-qa-db-ja.com

「NoClassDefFoundError:org / Apache / logging / log4j / util / ReflectionUtil」が表示されます

Build.gradleファイルに次の依存関係があります。

compile 'org.slf4j:slf4j-api:1.7.25'
compile group: 'org.Apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
compile group: 'org.Apache.logging.log4j', name: 'log4j-api', version: '2.11.1'

単体テストを実行すると、次のログが表示されます。

exclude patterns:SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in 
[jar:file:....gradle/caches/modules-2/files-2.1/org.Apache.logging.log4j/log4j-slf4j-impl/2.7/382b070836b8940a02d28c936974db95e9bfc3a4/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/z002qz1/.gradle/caches/modules-2/files-2.1/org.Apache.logging.log4j/log4j-slf4j-impl/2.9.1/a97a849b18b3798c4af1a2ca5b10c66cef17e3a/log4j-slf4j-impl-2.9.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.Apache.logging.slf4j.Log4jLoggerFactory]
Java.lang.NoClassDefFoundError: org/Apache/logging/log4j/util/ReflectionUtil
at org.Apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.Java:42)
at org.Apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.Java:46)
at org.Apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.Java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.Java:358)

Springboot 2.0.4.RELEASEを使用しています。これが何らかのバージョンの不一致の問題であることを願っています。どんな洞察も大歓迎です。

6
hisdudeness

エラー: Java.lang.NoClassDefFoundError: org/Apache/logging/log4j/util/ReflectionUtil

これは、バージョン2.9.0以降のlog4j2がAPI jar(log4j-api-2.x.x.jar)からそのクラスを削除したためです。

最後のバージョンは2.8.2です。

クラスパスにバージョンが混在している可能性があります。

10
devwebcl

スプリングブートでlog4j2を構成する正しい方法は次のとおりです。

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-log4j2'
}

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

ドキュメントで説明 です。

1
Strelok