Skip to content

Changes to Log4J2LoggingSystem in 4.0.4 breaks with log4j-spring-boot #49703

Closed as not planned

Description

@elmuerte

After upgrading to 4.0.4 the application will no longer start when using log4j2 with the log4j-spring-boot extension when packaged in a fat-jar.

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:106)
        at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:64)
        at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)
Caused by: java.lang.IllegalAccessError: class org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem tried to access method 'void org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.<init>(java.lang.ClassLoader)' (org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem and org.springframework.boot.logging.log4j2.Log4J2LoggingSystem are in unnamed module of loader org.springframework.boot.loader.launch.LaunchedClassLoader @3f91beef)
        at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.<init>(Log4j2SpringBootLoggingSystem.java:77)
        at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem$Factory.getLoggingSystem(Log4j2SpringBootLoggingSystem.java:266)
        at org.springframework.boot.logging.DelegatingLoggingSystemFactory.getLoggingSystem(DelegatingLoggingSystemFactory.java:46)
        at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:170)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:239)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:222)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:180)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:173)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:151)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:137)
        at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:76)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:123)
        at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)

Activity

  1. added
    status: waiting-for-triage
    on Mar 23, 2026
  2. wilkinsona commented on Mar 23, 2026

    @wilkinsona
    Member

    Initially, I couldn't reproduce the described behavior, but I think I'd made some faulty assumptions. The problem isn't specific to running a fat jar and wasn't introduced in 4.0.4.

    It was introduced in 7d34320, which was a contribution from a Log4j2 maintainer which made the constructor package-private. We can consider making it public again but minimising the visibility is preferable.

    @ppkarwasz, what are the plans for Log4j2SpringBootLoggingSystem in relation to 7d34320.

    @elmuerte, for what purpose are you using log4j-spring-boot? You may not need it any more.

  3. added
    status: waiting-for-feedback
    on Mar 23, 2026
  4. elmuerte commented on Mar 23, 2026

    @elmuerte
    Author

    Looks like a few projects were still using it, but I see that it is no longer needed since Spring Boot 3 as all the features log4j-spring-boot provides the same functionality.
    So I'm removing that dependency where we are still using it.

    So, maybe add a notice to the release notes that people should remove log4j-spring-boot when upgrading to 4.0.4

  5. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    on Mar 23, 2026
  6. wilkinsona commented on Mar 23, 2026

    @wilkinsona
    Member

    The release notes for 3.0 already mentioned the new features in Boot's Log4j2 integration. I've updated the relevant section to also mention that a dependency on log4j-spring-boot can typically be removed.

  7. removed
    status: waiting-for-triage
    status: feedback-provided
    on Mar 23, 2026
  8. ppkarwasz commented on Mar 23, 2026

    @ppkarwasz
    Contributor

    Looks like a few projects were still using it, but I see that it is no longer needed since Spring Boot 3 as all the features log4j-spring-boot provides the same functionality.

    Hi @elmuerte,

    That is correct: log4j-spring-boot only targets Spring Boot 2, while in Spring Boot 3+ the module should be removed. We did document this fact, but apparently we missed some spots:

    We would love PRs that fix those pages. Log4j's documentation uses Antora and each page has an “Edit this page” link in the upper right corner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions