Spring 原始碼貼上3

2021-08-01 05:49:36 字數 2600 閱讀 6514

回到上面的那個注入發生第一現場setpropertyvalues(),看看裡面的具體實現setpropertyvalue()

public void setpropertyvalues(propertyvalues pvs, boolean ignoreunknown, boolean ignoreinvalid)

throws bean***ception

... }

public void setpropertyvalue(propertyvalue pv) throws bean***ception 

catch (notreadablepropertyexception ex)

tokens = getpropertynametokens(getfinalpath(nestedpa, propertyname));

if (nestedpa == this)

nestedpa.setpropertyvalue(tokens, pv);

} else

}

真正的注入開始

protected void setpropertyvalue(propertytokenholder tokens, propertyvalue pv) throws bean***ception 

catch (notreadablepropertyexception ex)

// set value for last key.

string key = tokens.keys[tokens.keys.length - 1];

if (propvalue == null)

else

}if (propvalue.getclass().isarray())

object convertedvalue = convertifnecessary(propertyname, oldvalue, pv.getvalue(),

requiredtype, ph.nested(tokens.keys.length));

int length = array.getlength(propvalue);

if (arrayindex >= length && arrayindex < this.autogrowcollectionlimit)

array.set(propvalue, arrayindex, convertedvalue);

}catch (indexoutofbound***ception ex)

}else if (propvalue instanceof list)

object convertedvalue = convertifnecessary(propertyname, oldvalue, pv.getvalue(),

requiredtype, ph.nested(tokens.keys.length));

int size = list.size();

if (index >= size && index < this.autogrowcollectionlimit)

catch (nullpointerexception ex)

}list.add(convertedvalue);

}else

catch (indexoutofbound***ception ex) }}

else if (propvalue instanceof map)

// pass full property name and old value in here, since we want full

// conversion ability for map values.

object convertedmapvalue = convertifnecessary(propertyname, oldvalue, pv.getvalue(),

mapvaluetype, ph.nested(tokens.keys.length));

map.put(convertedmapkey, convertedmapvalue);

}else

} else

return;

}else

}object oldvalue = null;

try

else

catch (exception ex)

if (logger.isdebugenabled()) }}

propertyname, oldvalue, originalvalue, ph.totypedescriptor());}}

}catch (typemismatchexception ex)

catch (invocationtargetexception ex)

else

throw new methodinvocationexception(propertychangeevent, cause);}}

catch (exception ex)

} }

現在通過propertyhandler這個類的封裝將反射操作都內聚了.

spring原始碼分析 spring原始碼分析

1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...

spring原始碼解析

spring源 解析 一 ioc容器 spring源 解析 二 ioc容器在web容器中的啟動 spring源 解析 三 spring jdbc spring源 解析 四 spring mvc spring源 解析 五 spring aop獲取proxy spring源 解析 六 spring宣告式...

Spring 原始碼分析

public throws bean ception 到這裡最終的方法就是refresh super只是做一些初始化工作,可以忽略。以下是初始化發放做的事情 debug main adding systemproperties propertysource with lowest search pr...