apache / apache/logging-log4j2

NoClassDefFoundError for org.apache.logging.log4j.spi.ExtendedLogger in Tomcat 11 with Java 21

Open
#3,504 6 comments 0 reactions 0 assignees View on GitHub
waiting-for-maintainer
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

### Problem Description
Our web application, which runs in Tomcat 11 and Java 21, uses **SLF4J + Logback** for logging. However, it allows dynamically importing extensions along with JARs at runtime using the server **classloader**. One of these extensions depends on `log4j-api-2.17.1.jar`, which is correctly present in the classpath.

After deploying the extension, **calling a service that uses Log4j results in the following error:**

`java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/ExtendedLogger`

The error mentioned above is being received by executing this line `Logger logger = LogManager.getLogger();` in extension service.

However, other Log4j classes, such as `LogManager` and `Logger`, are loading without issues.

### Environment Details

- **Application Type** : WAR-based Java web application

- **Application Server** : Apache Tomcat 11

- **Java Version** : 21

- **Logging Framework in Main App** : SLF4J with Logback

- **Extension Support** : Allows dynamic loading of JARs at runtime using the server classloader

- **Problematic Dependency** : log4j-api-2.17.1.jar (used by an extension)

### Debugging Steps & Findings

1. Verified that `log4j-api-2.17.1.jar` is present in the classpath and contains `org/apache/logging/log4j/spi/ExtendedLogger.class`.
2. Checked for multiple versions of `log4j-api` dependency in our application. **Result** : Only one instance of log4j-api-2.17.1.jar is found.
3. Printed the class loaders for Log4j classes:
```
System.out.println(org.apache.logging.log4j.LogManager.class);
System.out.println(org.apache.logging.log4j.Logger.class);
System.out.println(org.apache.logging.log4j.spi.ExtendedLogger.class);
```
**Result**:
`LogManager` and `Logger` printed correctly.
`ExtendedLogger.class` throws `NoClassDefFoundError`.

### Additional Notes

- **Same application worked in Tomcat 9 without requiring a restart.**

- **Tomcat 11 requires a restart for `ExtendedLogger` to be found.**

- **After restarting Tomcat 11, everything works correctly.**

### Request for Help

We need guidance on :

- Why is `ExtendedLogger` missing, even though other Log4j classes load fine?

- Does Tomcat 11’s classloader affect Log4j differently compared to Tomcat 9?

- Are there additional configurations we should try in Tomcat 11?

Would appreciate any insights from the community!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the extension service call to `LogManager.getLogger()` in the Tomcat 11, Java 21 WAR deployment, then compare class loading before and after a restart. Investigate the dynamically loaded `log4j-api-2.17.1.jar` and the reported `ExtendedLogger` failure; done means explaining the difference from Tomcat 9 and identifying any required configuration or reproducible project change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.