|
|
|
@ -116,6 +116,12 @@ class ConfigurationClassEnhancer { |
|
|
|
boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader()); |
|
|
|
boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader()); |
|
|
|
if (classLoaderMismatch && classLoader instanceof SmartClassLoader smartClassLoader) { |
|
|
|
if (classLoaderMismatch && classLoader instanceof SmartClassLoader smartClassLoader) { |
|
|
|
classLoader = smartClassLoader.getOriginalClassLoader(); |
|
|
|
classLoader = smartClassLoader.getOriginalClassLoader(); |
|
|
|
|
|
|
|
classLoaderMismatch = (classLoader != configClass.getClassLoader()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Use original ClassLoader if config class relies on package visibility
|
|
|
|
|
|
|
|
if (classLoaderMismatch && reliesOnPackageVisibility(configClass)) { |
|
|
|
|
|
|
|
classLoader = configClass.getClassLoader(); |
|
|
|
|
|
|
|
classLoaderMismatch = false; |
|
|
|
} |
|
|
|
} |
|
|
|
Enhancer enhancer = newEnhancer(configClass, classLoader); |
|
|
|
Enhancer enhancer = newEnhancer(configClass, classLoader); |
|
|
|
Class<?> enhancedClass = createClass(enhancer, classLoaderMismatch); |
|
|
|
Class<?> enhancedClass = createClass(enhancer, classLoaderMismatch); |
|
|
|
@ -132,6 +138,26 @@ class ConfigurationClassEnhancer { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Checks whether the given config class relies on package visibility, |
|
|
|
|
|
|
|
* either for the class itself or for any of its {@code @Bean} methods. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean reliesOnPackageVisibility(Class<?> configSuperClass) { |
|
|
|
|
|
|
|
int mod = configSuperClass.getModifiers(); |
|
|
|
|
|
|
|
if (!Modifier.isPublic(mod) && !Modifier.isProtected(mod)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (Method method : ReflectionUtils.getDeclaredMethods(configSuperClass)) { |
|
|
|
|
|
|
|
if (BeanAnnotationHelper.isBeanAnnotated(method)) { |
|
|
|
|
|
|
|
mod = method.getModifiers(); |
|
|
|
|
|
|
|
if (!Modifier.isPublic(mod) && !Modifier.isProtected(mod)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a new CGLIB {@link Enhancer} instance. |
|
|
|
* Creates a new CGLIB {@link Enhancer} instance. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|