Apply fallback in case of initial SmartClassLoader mismatch as well

See gh-34423
This commit is contained in:
Juergen Hoeller 2025-02-18 20:40:13 +01:00
parent 93134fd4d1
commit 6786e1c3e5
1 changed files with 3 additions and 5 deletions

View File

@ -112,12 +112,11 @@ class ConfigurationClassEnhancer {
try { try {
// Use original ClassLoader if config class not locally loaded in overriding class loader // Use original ClassLoader if config class not locally loaded in overriding class loader
if (classLoader instanceof SmartClassLoader smartClassLoader && boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader());
classLoader != configClass.getClassLoader()) { if (classLoaderMismatch && classLoader instanceof SmartClassLoader smartClassLoader) {
classLoader = smartClassLoader.getOriginalClassLoader(); classLoader = smartClassLoader.getOriginalClassLoader();
} }
Enhancer enhancer = newEnhancer(configClass, classLoader); Enhancer enhancer = newEnhancer(configClass, classLoader);
boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader());
Class<?> enhancedClass = createClass(enhancer, classLoaderMismatch); Class<?> enhancedClass = createClass(enhancer, classLoaderMismatch);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace(String.format("Successfully enhanced %s; enhanced class name is: %s", 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. * Marker interface to be implemented by all @Configuration CGLIB subclasses.
* Facilitates idempotent behavior for {@link ConfigurationClassEnhancer#enhance} * Facilitates idempotent behavior for {@link ConfigurationClassEnhancer#enhance}
* through checking to see if candidate classes are already assignable to it, for example, * through checking to see if candidate classes are already assignable to it.
* have already been enhanced.
* <p>Also extends {@link BeanFactoryAware}, as all enhanced {@code @Configuration} * <p>Also extends {@link BeanFactoryAware}, as all enhanced {@code @Configuration}
* classes require access to the {@link BeanFactory} that created them. * classes require access to the {@link BeanFactory} that created them.
* <p>Note that this interface is intended for framework-internal use only, however * <p>Note that this interface is intended for framework-internal use only, however