Skip to content

ClassNotFoundException Found when run quartz task by CompletableFuture.runAsync #47302

@NoahArno

Description

@NoahArno

After upgrading Spring Boot from version 2.7.18 to 3.4.5, I was using CompletableFuture.runAsync to execute scheduled tasks. However, after the upgrade, these scheduled tasks could no longer be executed and would throw a ClassNotFoundException, specifically in the ResourceLoaderClassLoadHelper#loadClass(String name)method.

Interestingly, this problem didn't occur when I started the project locally through IDEA - it only appeared when starting the application from the packaged JAR (which worked fine before the upgrade).

Ultimately, I resolved the issue by manually specifying an Executor for CompletableFuture. However, I'm still unclear about the exact underlying mechanism that caused this behavior.

​Additional Technical Context:​​

This issue likely relates to Spring Boot 3.x's enhanced module system and class loading isolation, where asynchronous tasks might lose thread context class loader visibility when no explicit executor is provided. The manual executor specification probably preserves the correct class loader context.

I provided a demo project to reproduce this error. The project uses MySQL database and can initialize data using demo.sql. After the project is packaged in a jar file, run it using Java jar and call the/app/jobs/create interface, and ClassNotFoundException will be found。

see demo project: https://github.com/NoahArno/quartz_async_error_demo

the exception capture is:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions