Avoid hard-coded SCOPED_TARGET_PREFIX usage. (#811)

Co-authored-by: Spencer Gibb <sgibb@pivotal.io>
This commit is contained in:
Ian Hu
2021-02-18 00:34:59 +08:00
committed by GitHub
parent 36d5350661
commit e42f0987bb
8 changed files with 18 additions and 16 deletions

View File

@@ -73,11 +73,6 @@ import org.springframework.util.StringUtils;
public class GenericScope
implements Scope, BeanFactoryPostProcessor, BeanDefinitionRegistryPostProcessor, DisposableBean {
/**
* Prefix for the scoped target.
*/
public static final String SCOPED_TARGET_PREFIX = "scopedTarget.";
private static final Log logger = LogFactory.getLog(GenericScope.class);
private BeanLifecycleWrapperCache cache = new BeanLifecycleWrapperCache(new StandardScopeCache());

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.context.scope.refresh;
import java.io.Serializable;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -132,10 +133,10 @@ public class RefreshScope extends GenericScope
@ManagedOperation(description = "Dispose of the current instance of bean name "
+ "provided and force a refresh on next method execution.")
public boolean refresh(String name) {
if (!name.startsWith(SCOPED_TARGET_PREFIX)) {
if (!ScopedProxyUtils.isScopedTarget(name)) {
// User wants to refresh the bean with this name but that isn't the one in the
// cache...
name = SCOPED_TARGET_PREFIX + name;
name = ScopedProxyUtils.getTargetBeanName(name);
}
// Ensure lifecycle is finished if bean was disposable
if (super.destroy(name)) {