From 6786e1c3e591e820282d9febe198dee363a292cf Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 18 Feb 2025 20:40:13 +0100 Subject: [PATCH] Apply fallback in case of initial SmartClassLoader mismatch as well See gh-34423 --- .../context/annotation/ConfigurationClassEnhancer.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java index bd8607d4dc..9b50adddef 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java @@ -112,12 +112,11 @@ class ConfigurationClassEnhancer { try { // Use original ClassLoader if config class not locally loaded in overriding class loader - if (classLoader instanceof SmartClassLoader smartClassLoader && - classLoader != configClass.getClassLoader()) { + boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader()); + if (classLoaderMismatch && classLoader instanceof SmartClassLoader smartClassLoader) { classLoader = smartClassLoader.getOriginalClassLoader(); } Enhancer enhancer = newEnhancer(configClass, classLoader); - boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader()); Class enhancedClass = createClass(enhancer, classLoaderMismatch); if (logger.isTraceEnabled()) { logger.trace(String.format("Successfully enhanced %s; enhanced class name is: %s", @@ -188,8 +187,7 @@ class ConfigurationClassEnhancer { /** * Marker interface to be implemented by all @Configuration CGLIB subclasses. * Facilitates idempotent behavior for {@link ConfigurationClassEnhancer#enhance} - * through checking to see if candidate classes are already assignable to it, for example, - * have already been enhanced. + * through checking to see if candidate classes are already assignable to it. *

Also extends {@link BeanFactoryAware}, as all enhanced {@code @Configuration} * classes require access to the {@link BeanFactory} that created them. *

Note that this interface is intended for framework-internal use only, however