Bug Report: ClassNotFoundException when enabling DEBUG logging for org.springframework.ai Spring AI version: 1.0.1 Spring Boot version: 3.5.5 Java version: 21
Description: When setting the logging level to DEBUG for org.springframework.ai, the application fails to start due to a ClassNotFoundException. However, using INFO level works without issues. This behavior makes logging level affect runtime stability, which should not happen.
Steps to Reproduce: 1. Create a Spring Boot project with Spring AI 1.0.1. 2. Do not add the spring-security-oauth2-client dependency. 3.Configure logging in application.properties: logging.level.org.springframework.ai=DEBUG 4. Run the application.
Actual Behavior: Application fails with: java.lang.ClassNotFoundException: org.springframework.security.oauth2.client.ClientAuthorizationException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ... at org.springframework.ai.model.tool.autoconfigure.ToolCallingAutoConfiguration.toolExecutionExceptionProcessor(ToolCallingAutoConfiguration.java:87) ...
Expected Behavior: Enabling DEBUG logging should not trigger ClassNotFoundException. If spring-security-oauth2-client is not present, Spring AI should gracefully skip OAuth2-related configuration. Logging level should never change the runtime behavior of auto-configuration.
Comment From: dafriz
Tried to reproduce, I get the stack trace:
...ToolCallingAutoConfiguration : Cannot load class
java.lang.ClassNotFoundException: org.springframework.security.oauth2.client.ClientAuthorizationException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:534) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:513) ~[na:na]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:321) ~[spring-core-6.2.10.jar:6.2.10]
at org.springframework.ai.model.tool.autoconfigure.ToolCallingAutoConfiguration.getClassOrNull(ToolCallingAutoConfiguration.java:128) ~[spring-ai-autoconfigure-model-tool-1.0.1.jar:1.0.1]
but the app still starts up. Are there any other missing steps to reproduce a failed start?
The code is
} catch (ClassNotFoundException e) {
logger.debug("Cannot load class", e);
return null;
}
We should probably change to log just the missing class and not the stack trace.
Comment From: dafriz
Just noticed this issue duplicates https://github.com/spring-projects/spring-ai/issues/4205
Some context, the reason Spring AI is looking for this class is https://github.com/spring-projects/spring-ai/pull/3595
Comment From: chenzibiao
The application still starts up successfully — it does not actually fail to run. So functionally everything works, but the exception output is misleading and makes it look like something is wrong, even though the app is running normally.
Comment From: sunyuhan1998
Thank you all for the reports and discussion. I've attempted to submit a PR to adjust the log message—could everyone please help review it? Thanks! #4257