传递性 log4j2 依赖 - 配置失败

Transitive log4j2 dependency - configuration failing

我正在处理一个将 log4j2 作为传递依赖项的项目。 我遇到了这个错误

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

所以我在 src/main/resources 下创建了一个新的 log4j2.xml 文件,并尝试使用默认的 Apache 配置。

此处:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

现在,当我构建我的项目时,这个 warns(错误)提示:

 2015-02-11 17:02:52,375 WARN JNDI lookup class is not available because this JRE does not support JNDI. JNDI string lookups will not be available, continuing configuration. java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.lookup.JndiLookup to org.apache.logging.log4j.core.lookup.StrLookup
    at java.lang.Class.cast(Class.java:3133)
    at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
    at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
    at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:92)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:104)
    at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:55)
    at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:375)
    at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:280)
    at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.<init>(ConsoleAppender.java:116)
    at org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder(ConsoleAppender.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:158)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:118)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:698)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:358)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:359)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:420)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:102)
    at org.apache.logging.log4j.jcl.LogAdapter.getContext(LogAdapter.java:39)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
    at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:40)
    at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:55)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
    at org.mule.util.IOUtils.<clinit>(IOUtils.java:33)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.getExamplesFile(JavaDocAnnotationVerifier.java:222)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.validateSampleTag(JavaDocAnnotationVerifier.java:199)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.validateMethod(JavaDocAnnotationVerifier.java:143)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.verify(JavaDocAnnotationVerifier.java:74)
    at org.mule.devkit.verifiers.SimpleJavaDocAnnotationVerifier.verify(SimpleJavaDocAnnotationVerifier.java:17)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.doVerify(AbstractAnnotationProcessor.java:462)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.verifyModule(AbstractAnnotationProcessor.java:307)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.runVerifiers(AbstractAnnotationProcessor.java:185)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.doProcess(AbstractAnnotationProcessor.java:413)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.process(AbstractAnnotationProcessor.java:140)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access00(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
    at org.mule.devkit.maven.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled(AbstractAnnotationProcessorMojo.java:231)
    at org.mule.devkit.maven.AbstractAnnotationProcessorMojo.execute(AbstractAnnotationProcessorMojo.java:149)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

2015-02-11 17:02:52,379 WARN JMX runtime input lookup class is not available because this JRE does not support JMX. JMX lookups will not be available, continuing configuration. java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup to org.apache.logging.log4j.core.lookup.StrLookup
    at java.lang.Class.cast(Class.java:3133)
    at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
    at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
    at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:103)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:104)
    at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:55)
    at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:375)
    at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:280)
    at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.<init>(ConsoleAppender.java:116)
    at org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder(ConsoleAppender.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:158)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:118)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:698)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:358)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:359)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:420)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:102)
    at org.apache.logging.log4j.jcl.LogAdapter.getContext(LogAdapter.java:39)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
    at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:40)
    at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:55)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
    at org.mule.util.IOUtils.<clinit>(IOUtils.java:33)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.getExamplesFile(JavaDocAnnotationVerifier.java:222)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.validateSampleTag(JavaDocAnnotationVerifier.java:199)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.validateMethod(JavaDocAnnotationVerifier.java:143)
    at org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.verify(JavaDocAnnotationVerifier.java:74)
    at org.mule.devkit.verifiers.SimpleJavaDocAnnotationVerifier.verify(SimpleJavaDocAnnotationVerifier.java:17)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.doVerify(AbstractAnnotationProcessor.java:462)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.verifyModule(AbstractAnnotationProcessor.java:307)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.runVerifiers(AbstractAnnotationProcessor.java:185)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.doProcess(AbstractAnnotationProcessor.java:413)
    at org.mule.devkit.apt.AbstractAnnotationProcessor.process(AbstractAnnotationProcessor.java:140)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access00(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
    at org.mule.devkit.maven.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled(AbstractAnnotationProcessorMojo.java:231)
    at org.mule.devkit.maven.AbstractAnnotationProcessorMojo.execute(AbstractAnnotationProcessorMojo.java:149)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

当前依赖版本:

这可能是什么原因造成的?

提前致谢。

胡娟:

也许该项目还在某处加载了另一个依赖于 JMX 属性的 log4j2 配置。您可以通过在您的配置文件上启用 DEBUG 或 TRACE 状态来获取有关 Log4j 正在做什么的更多信息,如图所示 here

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG" name="example-config">
</Configuration>

还尝试通过传入系统 属性 将 Log4j 的默认 StatusLogger 设置为 DEBUG,当 运行 应用程序时:

java -DLog4jDefaultStatusLevel=DEBUG MyApp

此外,您确定类路径中没有 1.2 依赖项吗?如果有,它们可能与 1.2-2.1 桥冲突。

这不是问题。 Interpolator class 正在尝试启用各种查找:例如 env:propertyName 查找环境变量,sys:propertyName 查找 Java 系统属性,jndi:propertyName 用于 JNDI 属性等

如果 JNDI 不可用,您将看到此警告。记录此消息后配置将继续。

您可以在 log4j2 Jira 问题跟踪器上提出请求,使这看起来不像是错误(事后看来,堆栈跟踪在这里令人困惑且不必要)。