Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
2.0-beta8
-
None
-
None
Description
Shouldn't we disable JMX by default?
I see currently in Log4jContextFactory, the MBeans are being registered by default -
public Log4jContextFactory() { final String sel = PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR); if (sel != null) { try { final Class<?> clazz = Loader.loadClass(sel); if (clazz != null && ContextSelector.class.isAssignableFrom(clazz)) { selector = (ContextSelector) clazz.newInstance(); } } catch (final Exception ex) { LOGGER.error("Unable to create context " + sel, ex); } } if (selector == null) { selector = new ClassLoaderContextSelector(); } try { Server.registerMBeans(selector); } catch (final Exception ex) { LOGGER.error("Could not start JMX", ex); } }
The is causing errors in my standalone java application which is a simple console utility.
I am getting the following error as Log4j tries to register MBeans -
java.lang.IllegalAccessError: tried to access method javax.management.StandardMBean.<init>(Ljava/lang/Object;Ljava/lang/Class;Z)V from class sun.management.ManagementFactory at sun.management.ManagementFactory.addMXBean(ManagementFactory.java:249) at sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:304) at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504) at org.apache.logging.log4j.core.jmx.Server.registerMBeans(Server.java:107) at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:59) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:85) at org.slf4j.helpers.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:90) at org.slf4j.helpers.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:46) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281) at com.labcorp.eag.util.jms.SaveQueueToFiles.<clinit>(SaveQueueToFiles.java:45) Exception in thread "main"
Currently I overcome this error by setting
-Dlog4j2.disable.jmx=true
Attachments
Issue Links
- is related to
-
LOG4J2-321 Provide configuration alternative to system properties
- Closed
-
LOG4J2-324 Potential performance improvement for StatusLogger
- Closed