spring中 THreadLocal 的运用地方

1.aop 代理xx 在真正对普通bean作为tartget创建代理proxy对象前,
先是找该类所对应所有的可以适配的 通知类集合时,
在 AbstarctAdvisorAutoProxyCreator 中

protected List<Advisor> findAdvisorsThatCanApply(
			List<Advisor> candidateAdvisors, Class<?> beanClass, String beanName) {

		ProxyCreationContext.setCurrentProxiedBeanName(beanName);
		try {
			return AopUtils.findAdvisorsThatCanApply(candidateAdvisors, beanClass);
		}
		finally {
			ProxyCreationContext.setCurrentProxiedBeanName(null);
		}
	}

而那个setxxxName 就是
加粗样式

public class ProxyCreationContext {

	/** ThreadLocal holding the current proxied bean name during Advisor matching */
	private static final ThreadLocal<String> currentProxiedBeanName =
			new NamedThreadLocal<>("Name of currently proxied bean");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章