创建Logger时Log4j2和InstanceAlreadyExistsException

时间:2015-10-13 14:30:26

标签: log4j2 loggerfactory

我从log4j移动到log4j2并看到以下异常堆栈,
在打电话时:

private static final Logger LOG = LoggerFactory.getLogger(com.mine.pto.ejb_access.MyClass.class);

在应用程序中使用多个线程时,有时会抛出异常。

知道我对Log4j2做错了什么吗?

2015-10-13 16:18:48,029 ERROR Could not register mbeans javax.management.InstanceAlreadyExistsException: org.apache.logging.log4j2:type=1304568236,component=Loggers,name=com.mine.pto.ejb_access
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:513)
at org.apache.logging.log4j.core.jmx.Server.register(Server.java:375)
at org.apache.logging.log4j.core.jmx.Server.registerLoggerConfigs(Server.java:344)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:182)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:143)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:372)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:426)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:442)
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.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:285)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305)
...

1 个答案:

答案 0 :(得分:0)

这可能是https://issues.apache.org/jira/browse/LOG4J2-1094的重复。

如果是这样,修复是在启动任何线程之前调用LoggerFactory.getLogger()