|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -22,6 +22,7 @@ import java.lang.reflect.Method; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aot.AotDetector; |
|
|
|
import org.springframework.beans.BeanInstantiationException; |
|
|
|
import org.springframework.beans.BeanInstantiationException; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.BeanFactory; |
|
|
|
import org.springframework.beans.factory.BeanFactory; |
|
|
|
@ -153,7 +154,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt |
|
|
|
Enhancer enhancer = new Enhancer(); |
|
|
|
Enhancer enhancer = new Enhancer(); |
|
|
|
enhancer.setSuperclass(beanDefinition.getBeanClass()); |
|
|
|
enhancer.setSuperclass(beanDefinition.getBeanClass()); |
|
|
|
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); |
|
|
|
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); |
|
|
|
enhancer.setAttemptLoad(true); |
|
|
|
enhancer.setAttemptLoad(AotDetector.useGeneratedArtifacts()); |
|
|
|
if (this.owner instanceof ConfigurableBeanFactory cbf) { |
|
|
|
if (this.owner instanceof ConfigurableBeanFactory cbf) { |
|
|
|
ClassLoader cl = cbf.getBeanClassLoader(); |
|
|
|
ClassLoader cl = cbf.getBeanClassLoader(); |
|
|
|
enhancer.setStrategy(new ClassLoaderAwareGeneratorStrategy(cl)); |
|
|
|
enhancer.setStrategy(new ClassLoaderAwareGeneratorStrategy(cl)); |
|
|
|
@ -265,7 +266,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* CGLIB MethodInterceptor to override methods, replacing them with a call |
|
|
|
* CGLIB MethodInterceptor to override methods, replacing them with a call |
|
|
|
* to a generic MethodReplacer. |
|
|
|
* to a generic {@link MethodReplacer}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static class ReplaceOverrideMethodInterceptor extends CglibIdentitySupport implements MethodInterceptor { |
|
|
|
private static class ReplaceOverrideMethodInterceptor extends CglibIdentitySupport implements MethodInterceptor { |
|
|
|
|
|
|
|
|
|
|
|
@ -277,10 +278,10 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Nullable |
|
|
|
public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { |
|
|
|
public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { |
|
|
|
ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method); |
|
|
|
ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method); |
|
|
|
Assert.state(ro != null, "ReplaceOverride not found"); |
|
|
|
Assert.state(ro != null, "ReplaceOverride not found"); |
|
|
|
// TODO could cache if a singleton for minor performance optimization
|
|
|
|
|
|
|
|
MethodReplacer mr = this.owner.getBean(ro.getMethodReplacerBeanName(), MethodReplacer.class); |
|
|
|
MethodReplacer mr = this.owner.getBean(ro.getMethodReplacerBeanName(), MethodReplacer.class); |
|
|
|
return mr.reimplement(obj, method, args); |
|
|
|
return mr.reimplement(obj, method, args); |
|
|
|
} |
|
|
|
} |
|
|
|
|