Skip to content

Provide option to re-enable log4j2 JMX support when they disable it by default #40273

Closed as not planned
@sdavids

Description

@sdavids
configurations {
  implementation {
    exclude(module = "spring-boot-starter-logging")
  }
}

dependencies {
  implementation("org.springframework.boot:spring-boot-starter")
  implementation("org.springframework.boot:spring-boot-starter-log4j2")
  testImplementation("org.springframework.boot:spring-boot-starter-test")
}
package com.example.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jmx.support.MBeanServerFactoryBean;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
class DemoApplicationTests {

  @Test
  void contextLoads() {
    var factory = new MBeanServerFactoryBean();
    factory.setLocateExistingServerIfPossible(true);
    factory.afterPropertiesSet();
    var server = factory.getObject();
    assertThat(server.getDomains()).doesNotContain("org.apache.logging.log4j2"); // fails
  }
}

JMX support is enabled by default.

https://logging.apache.org/log4j/2.x/manual/jmx.html#enabling-jmx

Related

Spring Boot - Disable JMX by default

JUnit 5 - Disable Log4J JMX beans creation in tests


Ideally the auto-configuration would set log4j2.disableJmx=true if spring.jmx.enabled=false thereby no log4j2 JMX beans would be created.

Alternatively, the log4j2.disableJmx property should be mentioned in at least these two places:

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions