判斷是否支援jpa來註冊持久化bean處理器
// check for jpa support, and if present add the persistenceannotationbeanpostprocessor.
if (jpapresent && !registry.containsbeandefinition(persistence_annotation_processor_bean_name))
catch (classnotfoundexception ex)
def.setsource(source);
beandefs.add(registerpostprocessor(registry, def, persistence_annotation_processor_bean_name));
}if (!registry.containsbeandefinition(event_listener_processor_bean_name))
if (!registry.containsbeandefinition(event_listener_factory_bean_name))
註冊事件監聽處理器類eventlistenermethodprocessor,註冊預設事件***工廠
if (!registry.containsbeandefinition(event_listener_processor_bean_name))
if (!registry.containsbeandefinition(event_listener_factory_bean_name))
它實現了介面smartinitializingsingleton,在容器初始化最後會觸發方法aftersingletonsinstantiated
public void aftersingletonsinstantiated()
catch (throwable ex)
}if (type != null)
catch (throwable ex) }}
try
catch (throwable ex) }}
}}
獲取容器上下文中事件***工廠類
protected listgeteventlistene***ctories()
判斷bean名字是否是目標**範圍
private static final string target_name_prefix = "scopedtarget.";
public static boolean isscopedtarget(string beanname)
獲取bean型別
public static final string original_target_class_attribute =
conventions.getqualifiedattributename(autoproxyutils.class, "originaltargetclass");
public static class<?> determinetargetclass(configurablelistablebeanfactory beanfactory, string beanname)
if (beanfactory.containsbeandefinition(beanname))
} return beanfactory.gettype(beanname);
}
對bean進行處理,檢查型別的方法中是否還有註解eventlistener
protected void processbean(final listfactories, final string beanname, final class<?> targettype)
});}
catch (throwable ex)
}if (collectionutils.isempty(annotatedmethods))
}else
break;}}
}if (logger.isdebugenabled())
}}}
檢視***工廠是否支援該方法,然後建立對應的上下文***
} this.beanname = beanname;
this.method = method;
this.targetclass = targetclass;
this.bridgedmethod = bridgemethodresolver.findbridgedmethod(method);
eventlistener ann = annotatedelementutils.findmergedannotation(method, eventlistener.class);
this.declaredeventtypes = resolvedeclaredeventtypes(method, ann);
this.condition = (ann != null ? ann.condition() : null);
this.order = resolveorder(method);
this.methodkey = new annotatedelementkey(method, targetclass);}
初始化它的上下文屬性和事件表示式解析類,最後新增到上下文中
this.evaluator = evaluator;}
spring原始碼分析 spring原始碼分析
1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...
spring原始碼分析之FactoryBean
一般情況下,我們spring採用反射來例項化物件,可是spring也提供了另一種方式,既通過實現factorybean來描述bean的例項化過程。public inte ce factorybean 介面描述很簡單 獲取bean,獲取bean的型別,是否是單例 public class carpub...
Spring 原始碼分析
public throws bean ception 到這裡最終的方法就是refresh super只是做一些初始化工作,可以忽略。以下是初始化發放做的事情 debug main adding systemproperties propertysource with lowest search pr...