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");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章