Fix GenericScope so that multiple subclasses can live in the same context (non-static inner class cannot resolve parent bean)
This commit is contained in:
committed by
Spencer Gibb
parent
edb2f9ad2d
commit
e833dbaa37
@@ -256,6 +256,7 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
|
||||
if (getName().equals(root.getDecoratedDefinition().getBeanDefinition()
|
||||
.getScope())) {
|
||||
root.setBeanClass(LockedScopedProxyFactoryBean.class);
|
||||
root.getConstructorArgumentValues().addGenericArgumentValue(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,6 +312,10 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
|
||||
return this.name;
|
||||
}
|
||||
|
||||
protected ReadWriteLock getLock(String beanName) {
|
||||
return locks.get(beanName);
|
||||
}
|
||||
|
||||
private static class BeanLifecycleWrapperCache {
|
||||
|
||||
private final ScopeCache cache;
|
||||
@@ -432,11 +437,16 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LockedScopedProxyFactoryBean extends ScopedProxyFactoryBean
|
||||
implements MethodInterceptor {
|
||||
public static class LockedScopedProxyFactoryBean<S extends GenericScope>
|
||||
extends ScopedProxyFactoryBean implements MethodInterceptor {
|
||||
|
||||
private final S scope;
|
||||
private String targetBeanName;
|
||||
|
||||
public LockedScopedProxyFactoryBean(S scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
super.setBeanFactory(beanFactory);
|
||||
@@ -463,7 +473,7 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
|
||||
return invocation.proceed();
|
||||
}
|
||||
Object proxy = getObject();
|
||||
Lock lock = locks.get(this.targetBeanName).readLock();
|
||||
Lock lock = scope.getLock(this.targetBeanName).readLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (proxy instanceof Advised) {
|
||||
|
||||
Reference in New Issue
Block a user