-
Couldn't load subscription status.
- Fork 38.8k
Closed
Closed
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
I found that, when I use @Lazy on @Resource fields, Spring injects a lazy proxy.
The lazy proxy's TargetSource is not static, so every time I invoke a method on the lazy proxy, it calls beanFactory.resolveDependency() to resolve the target object.
Why doesn't Spring set the lazy proxy's TargetSource to static?
If so, it will be faster when invoking the lazy proxy's methods.
For example, in CommonAnnotationBeanPostProcessor:
protected Object buildLazyResourceProxy(final LookupElement element, final @Nullable String requestingBeanName) {
TargetSource ts = new TargetSource() {
@Override
public Class<?> getTargetClass() {
return element.lookupType;
}
@Override
public boolean isStatic() {
// this place: why not use "true"?
return false;
}
@Override
public Object getTarget() {
return getResource(element, requestingBeanName);
}
@Override
public void releaseTarget(Object target) {
}
};
// ...
} Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply