69閬揝pring闈㈣瘯棰樺拰绛旀
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了69閬揝pring闈㈣瘯棰樺拰绛旀相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
閾炬帴锛?a href="http://ifeve.com/spring-interview-questions-and-answers/">http://ifeve.com/spring-interview-questions-and-answers/
鍘熸枃锛?a href="http://www.javacodegeeks.com/2014/05/spring-interview-questions-and-answers.html%20">http://www.javacodegeeks.com/2014/05/spring-interview-questions-and-answers.html%20
Spring 姒傝堪
浠€涔堟槸spring?
Spring 鏄釜Java浼佷笟绾у簲鐢ㄧ殑寮€婧愬紑鍙戞鏋躲€係pring涓昏鐢ㄦ潵寮€鍙慗ava搴旂敤锛屼絾鏄湁浜涙墿灞曟槸閽堝鏋勫缓J2EE骞冲彴鐨剋eb搴旂敤銆係pring 妗嗘灦鐩爣鏄畝鍖朖ava浼佷笟绾у簲鐢ㄥ紑鍙戯紝骞堕€氳繃POJO涓哄熀纭€鐨勭紪绋嬫ā鍨嬩績杩涜壇濂界殑缂栫▼涔犳儻銆?/p>浣跨敤Spring妗嗘灦鐨勫ソ澶勬槸浠€涔堬紵
杞婚噺锛歋pring 鏄交閲忕殑锛屽熀鏈殑鐗堟湰澶х害2MB銆?
鎺у埗鍙嶈浆锛歋pring閫氳繃鎺у埗鍙嶈浆瀹炵幇浜嗘澗鏁h€﹀悎锛屽璞′滑缁欏嚭瀹冧滑鐨勪緷璧栵紝鑰屼笉鏄垱寤烘垨鏌ユ壘渚濊禆鐨勫璞′滑銆?
闈㈠悜鍒囬潰鐨勭紪绋?AOP)锛歋pring鏀寔闈㈠悜鍒囬潰鐨勭紪绋嬶紝骞朵笖鎶婂簲鐢ㄤ笟鍔¢€昏緫鍜岀郴缁熸湇鍔″垎寮€銆?
瀹瑰櫒锛歋pring 鍖呭惈骞剁鐞嗗簲鐢ㄤ腑瀵硅薄鐨勭敓鍛藉懆鏈熷拰閰嶇疆銆?
MVC妗嗘灦锛歋pring鐨刉EB妗嗘灦鏄釜绮惧績璁捐鐨勬鏋讹紝鏄疻eb妗嗘灦鐨勪竴涓緢濂界殑鏇夸唬鍝併€?
浜嬪姟绠$悊锛歋pring 鎻愪緵涓€涓寔缁殑浜嬪姟绠$悊鎺ュ彛锛屽彲浠ユ墿灞曞埌涓婅嚦鏈湴浜嬪姟涓嬭嚦鍏ㄥ眬浜嬪姟锛圝TA锛夈€?
寮傚父澶勭悊锛歋pring 鎻愪緵鏂逛究鐨凙PI鎶婂叿浣撴妧鏈浉鍏崇殑寮傚父锛堟瘮濡傜敱JDBC锛孒ibernate or JDO鎶涘嚭鐨勶級杞寲涓轰竴鑷寸殑unchecked 寮傚父銆?/p>Spring鐢卞摢浜涙ā鍧楃粍鎴?
浠ヤ笅鏄疭pring 妗嗘灦鐨勫熀鏈ā鍧楋細
Core module
Bean module
Context module
Expression Language module
JDBC module
ORM module
OXM module
Java Messaging Service(JMS) module
Transaction module
Web module
Web-Servlet module
Web-Struts module
Web-Portlet module鏍稿績瀹瑰櫒锛堝簲鐢ㄤ笂涓嬫枃) 妯″潡銆?
杩欐槸鍩烘湰鐨凷pring妯″潡锛屾彁渚泂pring 妗嗘灦鐨勫熀纭€鍔熻兘锛孊eanFactory 鏄?浠讳綍浠pring涓哄熀纭€鐨勫簲鐢ㄧ殑鏍稿績銆係pring 妗嗘灦寤虹珛鍦ㄦ妯″潡涔嬩笂锛屽畠浣縎pring鎴愪负涓€涓鍣ㄣ€?/p>BeanFactory 鈥?BeanFactory 瀹炵幇涓句緥銆?
Bean 宸ュ巶鏄伐鍘傛ā寮忕殑涓€涓疄鐜帮紝鎻愪緵浜嗘帶鍒跺弽杞姛鑳斤紝鐢ㄦ潵鎶婂簲鐢ㄧ殑閰嶇疆鍜屼緷璧栦粠姝g湡鐨勫簲鐢ㄤ唬鐮佷腑鍒嗙銆?
鏈€甯哥敤鐨凚eanFactory 瀹炵幇鏄疿mlBeanFactory 绫汇€?/p>XMLBeanFactory
鏈€甯哥敤鐨勫氨鏄痮rg.springframework.beans.factory.xml.XmlBeanFactory 锛屽畠鏍规嵁XML鏂囦欢涓殑瀹氫箟鍔犺浇beans銆傝瀹瑰櫒浠嶺ML 鏂囦欢璇诲彇閰嶇疆鍏冩暟鎹苟鐢ㄥ畠鍘诲垱寤轰竴涓畬鍏ㄩ厤缃殑绯荤粺鎴栧簲鐢ㄣ€?/p>瑙i噴AOP妯″潡
AOP妯″潡鐢ㄤ簬鍙戠粰鎴戜滑鐨凷pring搴旂敤鍋氶潰鍚戝垏闈㈢殑寮€鍙戯紝 寰堝鏀寔鐢盇OP鑱旂洘鎻愪緵锛岃繖鏍峰氨纭繚浜哠pring鍜屽叾浠朅OP妗嗘灦鐨勫叡閫氭€с€傝繖涓ā鍧楀皢鍏冩暟鎹紪绋嬪紩鍏pring銆?/p>瑙i噴JDBC鎶借薄鍜孌AO妯″潡銆?
閫氳繃浣跨敤JDBC鎶借薄鍜孌AO妯″潡锛屼繚璇佹暟鎹簱浠g爜鐨勭畝娲侊紝骞惰兘閬垮厤鏁版嵁搴撹祫婧愰敊璇叧闂鑷寸殑闂锛屽畠鍦ㄥ悇绉嶄笉鍚岀殑鏁版嵁搴撶殑閿欒淇℃伅涔嬩笂锛屾彁渚涗簡涓€涓粺涓€鐨勫紓甯歌闂眰銆傚畠杩樺埄鐢⊿pring鐨凙OP 妯″潡缁橲pring搴旂敤涓殑瀵硅薄鎻愪緵浜嬪姟绠$悊鏈嶅姟銆?/p>瑙i噴瀵硅薄/鍏崇郴鏄犲皠闆嗘垚妯″潡銆?
Spring 閫氳繃鎻愪緵ORM妯″潡锛屾敮鎸佹垜浠湪鐩存帴JDBC涔嬩笂浣跨敤涓€涓璞?鍏崇郴鏄犲皠鏄犲皠(ORM)宸ュ叿锛孲pring 鏀寔闆嗘垚涓绘祦鐨凮RM妗嗘灦锛屽Hiberate,JDO鍜?iBATIS SQL Maps銆係pring鐨勪簨鍔$鐞嗗悓鏍锋敮鎸佷互涓婃墍鏈塐RM妗嗘灦鍙奐DBC銆?/p>瑙i噴WEB 妯″潡銆?
Spring鐨刉EB妯″潡鏄瀯寤哄湪application context 妯″潡鍩虹涔嬩笂锛屾彁渚涗竴涓€傚悎web搴旂敤鐨勪笂涓嬫枃銆傝繖涓ā鍧椾篃鍖呮嫭鏀寔澶氱闈㈠悜web鐨勪换鍔★紝濡傞€忔槑鍦板鐞嗗涓枃浠朵笂浼犺姹傚拰绋嬪簭绾ц姹傚弬鏁扮殑缁戝畾鍒颁綘鐨勪笟鍔″璞°€傚畠涔熸湁瀵笿akarta Struts鐨勬敮鎸併€?/p>Spring閰嶇疆鏂囦欢
Spring閰嶇疆鏂囦欢鏄釜XML 鏂囦欢锛岃繖涓枃浠跺寘鍚簡绫讳俊鎭紝鎻忚堪浜嗗浣曢厤缃畠浠紝浠ュ強濡備綍鐩镐簰璋冪敤銆?/p>浠€涔堟槸Spring IOC 瀹瑰櫒锛?
Spring IOC 璐熻矗鍒涘缓瀵硅薄锛岀鐞嗗璞★紙閫氳繃渚濊禆娉ㄥ叆锛圖I锛夛紝瑁呴厤瀵硅薄锛岄厤缃璞★紝骞朵笖绠$悊杩欎簺瀵硅薄鐨勬暣涓敓鍛藉懆鏈熴€?/p>IOC鐨勪紭鐐规槸浠€涔堬紵
IOC 鎴?渚濊禆娉ㄥ叆鎶婂簲鐢ㄧ殑浠g爜閲忛檷鍒版渶浣庛€傚畠浣垮簲鐢ㄥ鏄撴祴璇曪紝鍗曞厓娴嬭瘯涓嶅啀闇€瑕佸崟渚嬪拰JNDI鏌ユ壘鏈哄埗銆傛渶灏忕殑浠d环鍜屾渶灏忕殑渚靛叆鎬т娇鏉炬暎鑰﹀悎寰椾互瀹炵幇銆侷OC瀹瑰櫒鏀寔鍔犺浇鏈嶅姟鏃剁殑楗挎眽寮忓垵濮嬪寲鍜屾噿鍔犺浇銆?/p>ApplicationContext閫氬父鐨勫疄鐜版槸浠€涔?
FileSystemXmlApplicationContext 锛氭瀹瑰櫒浠庝竴涓猉ML鏂囦欢涓姞杞絙eans鐨勫畾涔夛紝XML Bean 閰嶇疆鏂囦欢鐨勫叏璺緞鍚嶅繀椤绘彁渚涚粰瀹冪殑鏋勯€犲嚱鏁般€?
ClassPathXmlApplicationContext锛氭瀹瑰櫒涔熶粠涓€涓猉ML鏂囦欢涓姞杞絙eans鐨勫畾涔夛紝杩欓噷锛屼綘闇€瑕佹纭缃甤lasspath鍥犱负杩欎釜瀹瑰櫒灏嗗湪classpath閲屾壘bean閰嶇疆銆?
WebXmlApplicationContext锛氭瀹瑰櫒鍔犺浇涓€涓猉ML鏂囦欢锛屾鏂囦欢瀹氫箟浜嗕竴涓猈EB搴旂敤鐨勬墍鏈塨ean銆?/p>Bean 宸ュ巶鍜?Application contexts 鏈変粈涔堝尯鍒紵
Application contexts鎻愪緵涓€绉嶆柟娉曞鐞嗘枃鏈秷鎭紝涓€涓€氬父鐨勫仛娉曟槸鍔犺浇鏂囦欢璧勬簮锛堟瘮濡傞暅鍍忥級锛屽畠浠彲浠ュ悜娉ㄥ唽涓虹洃鍚櫒鐨刡ean鍙戝竷浜嬩欢銆傚彟澶栵紝鍦ㄥ鍣ㄦ垨瀹瑰櫒鍐呯殑瀵硅薄涓婃墽琛岀殑閭d簺涓嶅緱涓嶇敱bean宸ュ巶浠ョ▼搴忓寲鏂瑰紡澶勭悊鐨勬搷浣滐紝鍙互鍦ˋpplication contexts涓互澹版槑鐨勬柟寮忓鐞嗐€侫pplication contexts瀹炵幇浜哅essageSource鎺ュ彛锛岃鎺ュ彛鐨勫疄鐜颁互鍙彃鎷旂殑鏂瑰紡鎻愪緵鑾峰彇鏈湴鍖栨秷鎭殑鏂规硶銆?/p>涓€涓猄pring鐨勫簲鐢ㄧ湅璧锋潵璞′粈涔堬紵
涓€涓畾涔変簡涓€浜涘姛鑳界殑鎺ュ彛銆?
杩欏疄鐜板寘鎷睘鎬э紝瀹冪殑Setter 锛?getter 鏂规硶鍜屽嚱鏁扮瓑銆?
Spring AOP銆?
Spring 鐨刋ML 閰嶇疆鏂囦欢銆?
浣跨敤浠ヤ笂鍔熻兘鐨勫鎴风绋嬪簭銆?
渚濊禆娉ㄥ叆浠€涔堟槸Spring鐨勪緷璧栨敞鍏ワ紵
渚濊禆娉ㄥ叆锛屾槸IOC鐨勪竴涓柟闈紝鏄釜閫氬父鐨勬蹇碉紝瀹冩湁澶氱瑙i噴銆傝繖姒傚康鏄浣犱笉鐢ㄥ垱寤哄璞★紝鑰屽彧闇€瑕佹弿杩板畠濡備綍琚垱寤恒€備綘涓嶅湪浠g爜閲岀洿鎺ョ粍瑁呬綘鐨勭粍浠跺拰鏈嶅姟锛屼絾鏄鍦ㄩ厤缃枃浠堕噷鎻忚堪鍝簺缁勪欢闇€瑕佸摢浜涙湇鍔★紝涔嬪悗涓€涓鍣紙IOC瀹瑰櫒锛夎礋璐f妸浠栦滑缁勮璧锋潵銆?/p>鏈夊摢浜涗笉鍚岀被鍨嬬殑IOC锛堜緷璧栨敞鍏ワ級鏂瑰紡锛?
鏋勯€犲櫒渚濊禆娉ㄥ叆锛氭瀯閫犲櫒渚濊禆娉ㄥ叆閫氳繃瀹瑰櫒瑙﹀彂涓€涓被鐨勬瀯閫犲櫒鏉ュ疄鐜扮殑锛岃绫绘湁涓€绯诲垪鍙傛暟锛屾瘡涓弬鏁颁唬琛ㄤ竴涓鍏朵粬绫荤殑渚濊禆銆?
Setter鏂规硶娉ㄥ叆锛歋etter鏂规硶娉ㄥ叆鏄鍣ㄩ€氳繃璋冪敤鏃犲弬鏋勯€犲櫒鎴栨棤鍙俿tatic宸ュ巶 鏂规硶瀹炰緥鍖朾ean涔嬪悗锛岃皟鐢ㄨbean鐨剆etter鏂规硶锛屽嵆瀹炵幇浜嗗熀浜巗etter鐨勪緷璧栨敞鍏ャ€?/p>鍝渚濊禆娉ㄥ叆鏂瑰紡浣犲缓璁娇鐢紝鏋勯€犲櫒娉ㄥ叆锛岃繕鏄?Setter鏂规硶娉ㄥ叆锛?
浣犱袱绉嶄緷璧栨柟寮忛兘鍙互浣跨敤锛屾瀯閫犲櫒娉ㄥ叆鍜孲etter鏂规硶娉ㄥ叆銆傛渶濂界殑瑙e喅鏂规鏄敤鏋勯€犲櫒鍙傛暟瀹炵幇寮哄埗渚濊禆锛宻etter鏂规硶瀹炵幇鍙€変緷璧栥€?/p>
Spring Beans
浠€涔堟槸Spring beans?
Spring beans 鏄偅浜涘舰鎴怱pring搴旂敤鐨勪富骞茬殑java瀵硅薄銆傚畠浠Spring IOC瀹瑰櫒鍒濆鍖栵紝瑁呴厤锛屽拰绠$悊銆傝繖浜沚eans閫氳繃瀹瑰櫒涓厤缃殑鍏冩暟鎹垱寤恒€傛瘮濡傦紝浠ML鏂囦欢涓?鐨勫舰寮忓畾涔夈€?
Spring 妗嗘灦瀹氫箟鐨刡eans閮芥槸鍗曚欢beans銆傚湪bean tag涓湁涓睘鎬р€漵ingleton鈥濓紝濡傛灉瀹冭璧嬩负TRUE锛宐ean 灏辨槸鍗曚欢锛屽惁鍒欏氨鏄竴涓?prototype bean銆傞粯璁ゆ槸TRUE锛屾墍浠ユ墍鏈夊湪Spring妗嗘灦涓殑beans 缂虹渷閮芥槸鍗曚欢銆?/p>涓€涓?Spring Bean 瀹氫箟 鍖呭惈浠€涔堬紵
涓€涓猄pring Bean 鐨勫畾涔夊寘鍚鍣ㄥ繀鐭ョ殑鎵€鏈夐厤缃厓鏁版嵁锛屽寘鎷浣曞垱寤轰竴涓猙ean锛屽畠鐨勭敓鍛藉懆鏈熻鎯呭強瀹冪殑渚濊禆銆?/p>濡備綍缁橲pring 瀹瑰櫒鎻愪緵閰嶇疆鍏冩暟鎹?
杩欓噷鏈変笁绉嶉噸瑕佺殑鏂规硶缁橲pring 瀹瑰櫒鎻愪緵閰嶇疆鍏冩暟鎹€?
XML閰嶇疆鏂囦欢銆?
鍩轰簬娉ㄨВ鐨勯厤缃€?
鍩轰簬java鐨勯厤缃€?/p>浣犳€庢牱瀹氫箟绫荤殑浣滅敤鍩?
褰撳畾涔変竴涓?code><bean> 鍦⊿pring閲岋紝鎴戜滑杩樿兘缁欒繖涓猙ean澹版槑涓€涓綔鐢ㄥ煙銆傚畠鍙互閫氳繃bean 瀹氫箟涓殑scope灞炴€ф潵瀹氫箟銆傚锛屽綋Spring瑕佸湪闇€瑕佺殑鏃跺€欐瘡娆$敓浜т竴涓柊鐨刡ean瀹炰緥锛宐ean鐨剆cope灞炴€ц鎸囧畾涓簆rototype銆傚彟涓€鏂归潰锛屼竴涓猙ean姣忔浣跨敤鐨勬椂鍊欏繀椤昏繑鍥炲悓涓€涓疄渚嬶紝杩欎釜bean鐨剆cope 灞炴€?蹇呴』璁句负 singleton銆?/p>瑙i噴Spring鏀寔鐨勫嚑绉峛ean鐨勪綔鐢ㄥ煙銆?
Spring妗嗘灦鏀寔浠ヤ笅浜旂bean鐨勪綔鐢ㄥ煙锛?
singleton : bean鍦ㄦ瘡涓猄pring ioc 瀹瑰櫒涓彧鏈変竴涓疄渚嬨€?
prototype锛氫竴涓猙ean鐨勫畾涔夊彲浠ユ湁澶氫釜瀹炰緥銆?
request锛氭瘡娆ttp璇锋眰閮戒細鍒涘缓涓€涓猙ean锛岃浣滅敤鍩熶粎鍦ㄥ熀浜巜eb鐨凷pring ApplicationContext鎯呭舰涓嬫湁鏁堛€?
session锛氬湪涓€涓狧TTP Session涓紝涓€涓猙ean瀹氫箟瀵瑰簲涓€涓疄渚嬨€傝浣滅敤鍩熶粎鍦ㄥ熀浜巜eb鐨凷pring ApplicationContext鎯呭舰涓嬫湁鏁堛€?
global-session锛氬湪涓€涓叏灞€鐨凥TTP Session涓紝涓€涓猙ean瀹氫箟瀵瑰簲涓€涓疄渚嬨€傝浣滅敤鍩熶粎鍦ㄥ熀浜巜eb鐨凷pring ApplicationContext鎯呭舰涓嬫湁鏁堛€?
缂虹渷鐨凷pring bean 鐨勪綔鐢ㄥ煙鏄疭ingleton.Spring妗嗘灦涓殑鍗曚緥bean鏄嚎绋嬪畨鍏ㄧ殑鍚?
涓嶏紝Spring妗嗘灦涓殑鍗曚緥bean涓嶆槸绾跨▼瀹夊叏鐨勩€?/p>瑙i噴Spring妗嗘灦涓璪ean鐨勭敓鍛藉懆鏈熴€?
Spring瀹瑰櫒 浠嶺ML 鏂囦欢涓鍙朾ean鐨勫畾涔夛紝骞跺疄渚嬪寲bean銆?
Spring鏍规嵁bean鐨勫畾涔夊~鍏呮墍鏈夌殑灞炴€с€?
濡傛灉bean瀹炵幇浜咮eanNameAware 鎺ュ彛锛孲pring 浼犻€抌ean 鐨処D 鍒?setBeanName鏂规硶銆?
濡傛灉Bean 瀹炵幇浜?BeanFactoryAware 鎺ュ彛锛?Spring浼犻€抌eanfactory 缁檚etBeanFactory 鏂规硶銆?
濡傛灉鏈変换浣曚笌bean鐩稿叧鑱旂殑BeanPostProcessors锛孲pring浼氬湪postProcesserBeforeInitialization()鏂规硶鍐呰皟鐢ㄥ畠浠€?
濡傛灉bean瀹炵幇IntializingBean浜嗭紝璋冪敤瀹冪殑afterPropertySet鏂规硶锛屽鏋渂ean澹版槑浜嗗垵濮嬪寲鏂规硶锛岃皟鐢ㄦ鍒濆鍖栨柟娉曘€?
濡傛灉鏈塀eanPostProcessors 鍜宐ean 鍏宠仈锛岃繖浜沚ean鐨刾ostProcessAfterInitialization() 鏂规硶灏嗚璋冪敤銆?
濡傛灉bean瀹炵幇浜?DisposableBean锛屽畠灏嗚皟鐢╠estroy()鏂规硶銆?/p>鍝簺鏄噸瑕佺殑bean鐢熷懡鍛ㄦ湡鏂规硶锛?浣犺兘閲嶈浇瀹冧滑鍚楋紵
鏈変袱涓噸瑕佺殑bean 鐢熷懡鍛ㄦ湡鏂规硶锛岀涓€涓槸setup 锛?瀹冩槸鍦ㄥ鍣ㄥ姞杞絙ean鐨勬椂鍊欒璋冪敤銆傜浜屼釜鏂规硶鏄?teardown 瀹冩槸鍦ㄥ鍣ㄥ嵏杞界被鐨勬椂鍊欒璋冪敤銆?
The bean 鏍囩鏈変袱涓噸瑕佺殑灞炴€э紙init-method鍜宒estroy-method锛夈€傜敤瀹冧滑浣犲彲浠ヨ嚜宸卞畾鍒跺垵濮嬪寲鍜屾敞閿€鏂规硶銆傚畠浠篃鏈夌浉搴旂殑娉ㄨВ锛園PostConstruct鍜孈PreDestroy锛夈€?/p>浠€涔堟槸Spring鐨勫唴閮╞ean锛?
褰撲竴涓猙ean浠呰鐢ㄤ綔鍙︿竴涓猙ean鐨勫睘鎬ф椂锛屽畠鑳借澹版槑涓轰竴涓唴閮╞ean锛屼负浜嗗畾涔塱nner bean锛屽湪Spring 鐨?鍩轰簬XML鐨?閰嶇疆鍏冩暟鎹腑锛屽彲浠ュ湪 鎴? 鍏冪礌鍐呬娇鐢?鍏冪礌锛屽唴閮╞ean閫氬父鏄尶鍚嶇殑锛屽畠浠殑Scope涓€鑸槸prototype銆?/p>鍦?Spring涓浣曟敞鍏ヤ竴涓猨ava闆嗗悎锛?
Spring鎻愪緵浠ヤ笅鍑犵闆嗗悎鐨勯厤缃厓绱狅細
<list>
绫诲瀷鐢ㄤ簬娉ㄥ叆涓€鍒楀€硷紝鍏佽鏈夌浉鍚岀殑鍊笺€?
<set>
绫诲瀷鐢ㄤ簬娉ㄥ叆涓€缁勫€硷紝涓嶅厑璁告湁鐩稿悓鐨勫€笺€?
<map>
绫诲瀷鐢ㄤ簬娉ㄥ叆涓€缁勯敭鍊煎锛岄敭鍜屽€奸兘鍙互涓轰换鎰忕被鍨嬨€?
<props>
绫诲瀷鐢ㄤ簬娉ㄥ叆涓€缁勯敭鍊煎锛岄敭鍜屽€奸兘鍙兘涓篠tring绫诲瀷銆?/p>浠€涔堟槸bean瑁呴厤?
瑁呴厤锛屾垨bean 瑁呴厤鏄寚鍦⊿pring 瀹瑰櫒涓妸bean缁勮鍒颁竴璧凤紝鍓嶆彁鏄鍣ㄩ渶瑕佺煡閬揵ean鐨勪緷璧栧叧绯伙紝濡備綍閫氳繃渚濊禆娉ㄥ叆鏉ユ妸瀹冧滑瑁呴厤鍒颁竴璧枫€?/p>浠€涔堟槸bean鐨勮嚜鍔ㄨ閰嶏紵
Spring 瀹瑰櫒鑳藉鑷姩瑁呴厤鐩镐簰鍚堜綔鐨刡ean锛岃繖鎰忓懗鐫€瀹瑰櫒涓嶉渶瑕?code><constructor-arg>鍜?code><property>閰嶇疆锛岃兘閫氳繃Bean宸ュ巶鑷姩澶勭悊bean涔嬮棿鐨勫崗浣溿€?/p>瑙i噴涓嶅悓鏂瑰紡鐨勮嚜鍔ㄨ閰?銆?
鏈変簲绉嶈嚜鍔ㄨ閰嶇殑鏂瑰紡锛屽彲浠ョ敤鏉ユ寚瀵糞pring瀹瑰櫒鐢ㄨ嚜鍔ㄨ閰嶆柟寮忔潵杩涜渚濊禆娉ㄥ叆銆?
no锛氶粯璁ょ殑鏂瑰紡鏄笉杩涜鑷姩瑁呴厤锛岄€氳繃鏄惧紡璁剧疆ref 灞炴€ф潵杩涜瑁呴厤銆?
byName锛氶€氳繃鍙傛暟鍚?鑷姩瑁呴厤锛孲pring瀹瑰櫒鍦ㄩ厤缃枃浠朵腑鍙戠幇bean鐨刟utowire灞炴€ц璁剧疆鎴恇yname锛屼箣鍚庡鍣ㄨ瘯鍥惧尮閰嶃€佽閰嶅拰璇ean鐨勫睘鎬у叿鏈夌浉鍚屽悕瀛楃殑bean銆?
byType:锛氶€氳繃鍙傛暟绫诲瀷鑷姩瑁呴厤锛孲pring瀹瑰櫒鍦ㄩ厤缃枃浠朵腑鍙戠幇bean鐨刟utowire灞炴€ц璁剧疆鎴恇yType锛屼箣鍚庡鍣ㄨ瘯鍥惧尮閰嶃€佽閰嶅拰璇ean鐨勫睘鎬у叿鏈夌浉鍚岀被鍨嬬殑bean銆傚鏋滄湁澶氫釜bean绗﹀悎鏉′欢锛屽垯鎶涘嚭閿欒銆?
constructor锛氳繖涓柟寮忕被浼间簬byType锛?浣嗘槸瑕佹彁渚涚粰鏋勯€犲櫒鍙傛暟锛屽鏋滄病鏈夌‘瀹氱殑甯﹀弬鏁扮殑鏋勯€犲櫒鍙傛暟绫诲瀷锛屽皢浼氭姏鍑哄紓甯搞€?
autodetect锛氶鍏堝皾璇曚娇鐢╟onstructor鏉ヨ嚜鍔ㄨ閰嶏紝濡傛灉鏃犳硶宸ヤ綔锛屽垯浣跨敤byType鏂瑰紡銆?/p>鑷姩瑁呴厤鏈夊摢浜涘眬闄愭€??
鑷姩瑁呴厤鐨勫眬闄愭€ф槸锛?
閲嶅啓锛?浣犱粛闇€鐢?<constructor-arg>
鍜?code><property> 閰嶇疆鏉ュ畾涔変緷璧栵紝鎰忓懗鐫€鎬昏閲嶅啓鑷姩瑁呴厤銆?
鍩烘湰鏁版嵁绫诲瀷锛氫綘涓嶈兘鑷姩瑁呴厤绠€鍗曠殑灞炴€э紝濡傚熀鏈暟鎹被鍨嬶紝String瀛楃涓诧紝鍜岀被銆?
妯$硦鐗规€э細鑷姩瑁呴厤涓嶅鏄惧紡瑁呴厤绮剧‘锛屽鏋滄湁鍙兘锛屽缓璁娇鐢ㄦ樉寮忚閰嶃€?/p>浣犲彲浠ュ湪Spring涓敞鍏ヤ竴涓猲ull 鍜屼竴涓┖瀛楃涓插悧锛?
鍙互銆?/p>
Spring娉ㄨВ
浠€涔堟槸鍩轰簬Java鐨凷pring娉ㄨВ閰嶇疆? 缁欎竴浜涙敞瑙g殑渚嬪瓙.
鍩轰簬Java鐨勯厤缃紝鍏佽浣犲湪灏戦噺鐨凧ava娉ㄨВ鐨勫府鍔╀笅锛岃繘琛屼綘鐨勫ぇ閮ㄥ垎Spring閰嶇疆鑰岄潪閫氳繃XML鏂囦欢銆?
浠Configuration 娉ㄨВ涓轰緥锛屽畠鐢ㄦ潵鏍囪绫诲彲浠ュ綋鍋氫竴涓猙ean鐨勫畾涔夛紝琚玈pring IOC瀹瑰櫒浣跨敤銆傚彟涓€涓緥瀛愭槸@Bean娉ㄨВ锛屽畠琛ㄧず姝ゆ柟娉曞皢瑕佽繑鍥炰竴涓璞★紝浣滀负涓€涓猙ean娉ㄥ唽杩汼pring搴旂敤涓婁笅鏂囥€?/p>浠€涔堟槸鍩轰簬娉ㄨВ鐨勫鍣ㄩ厤缃?
鐩稿浜嶺ML鏂囦欢锛屾敞瑙e瀷鐨勯厤缃緷璧栦簬閫氳繃瀛楄妭鐮佸厓鏁版嵁瑁呴厤缁勪欢锛岃€岄潪灏栨嫭鍙风殑澹版槑銆?
寮€鍙戣€呴€氳繃鍦ㄧ浉搴旂殑绫伙紝鏂规硶鎴栧睘鎬т笂浣跨敤娉ㄨВ鐨勬柟寮忥紝鐩存帴缁勪欢绫讳腑杩涜閰嶇疆锛岃€屼笉鏄娇鐢▁ml琛ㄨ堪bean鐨勮閰嶅叧绯汇€?/p>鎬庢牱寮€鍚敞瑙h閰嶏紵
娉ㄨВ瑁呴厤鍦ㄩ粯璁ゆ儏鍐典笅鏄笉寮€鍚殑锛屼负浜嗕娇鐢ㄦ敞瑙h閰嶏紝鎴戜滑蹇呴』鍦⊿pring閰嶇疆鏂囦欢涓厤缃?<context:annotation-config/>
鍏冪礌銆?/p>@Required 娉ㄨВ
杩欎釜娉ㄨВ琛ㄦ槑bean鐨勫睘鎬у繀椤诲湪閰嶇疆鐨勬椂鍊欒缃紝閫氳繃涓€涓猙ean瀹氫箟鐨勬樉寮忕殑灞炴€у€兼垨閫氳繃鑷姩瑁呴厤锛岃嫢@Required娉ㄨВ鐨刡ean灞炴€ф湭琚缃紝瀹瑰櫒灏嗘姏鍑築eanInitializationException銆?/p>@Autowired 娉ㄨВ
@Autowired 娉ㄨВ鎻愪緵浜嗘洿缁嗙矑搴︾殑鎺у埗锛屽寘鎷湪浣曞浠ュ強濡備綍瀹屾垚鑷姩瑁呴厤銆傚畠鐨勭敤娉曞拰@Required涓€鏍凤紝淇グsetter鏂规硶銆佹瀯閫犲櫒銆佸睘鎬ф垨鑰呭叿鏈変换鎰忓悕绉板拰/鎴栧涓弬鏁扮殑PN鏂规硶銆?/p>@Qualifier 娉ㄨВ
褰撴湁澶氫釜鐩稿悓绫诲瀷鐨刡ean鍗村彧鏈変竴涓渶瑕佽嚜鍔ㄨ閰嶆椂锛屽皢@Qualifier 娉ㄨВ鍜孈Autowire 娉ㄨВ缁撳悎浣跨敤浠ユ秷闄よ繖绉嶆贩娣嗭紝鎸囧畾闇€瑕佽閰嶇殑纭垏鐨刡ean銆?/p>
Spring鏁版嵁璁块棶
鍦⊿pring妗嗘灦涓浣曟洿鏈夋晥鍦颁娇鐢↗DBC?
浣跨敤SpringJDBC 妗嗘灦锛岃祫婧愮鐞嗗拰閿欒澶勭悊鐨勪唬浠烽兘浼氳鍑忚交銆傛墍浠ュ紑鍙戣€呭彧闇€鍐檚tatements 鍜?queries浠庢暟鎹瓨鍙栨暟鎹紝JDBC涔熷彲浠ュ湪Spring妗嗘灦鎻愪緵鐨勬ā鏉跨被鐨勫府鍔╀笅鏇存湁鏁堝湴琚娇鐢紝杩欎釜妯℃澘鍙獼dbcTemplate 锛堜緥瀛愯杩欓噷here锛?/p>JdbcTemplate
JdbcTemplate 绫绘彁渚涗簡寰堝渚垮埄鐨勬柟娉曡В鍐宠濡傛妸鏁版嵁搴撴暟鎹浆鍙樻垚鍩烘湰鏁版嵁绫诲瀷鎴栧璞★紝鎵ц鍐欏ソ鐨勬垨鍙皟鐢ㄧ殑鏁版嵁搴撴搷浣滆鍙ワ紝鎻愪緵鑷畾涔夌殑鏁版嵁閿欒澶勭悊銆?/p>Spring瀵笵AO鐨勬敮鎸?
Spring瀵规暟鎹闂璞★紙DAO锛夌殑鏀寔鏃ㄥ湪绠€鍖栧畠鍜屾暟鎹闂妧鏈JDBC锛孒ibernate or JDO 缁撳悎浣跨敤銆傝繖浣挎垜浠彲浠ユ柟渚垮垏鎹㈡寔涔呭眰銆傜紪鐮佹椂涔熶笉鐢ㄦ媴蹇冧細鎹曡幏姣忕鎶€鏈壒鏈夌殑寮傚父銆?/p>浣跨敤Spring閫氳繃浠€涔堟柟寮忚闂瓾ibernate?
鍦⊿pring涓湁涓ょ鏂瑰紡璁块棶Hibernate锛?
鎺у埗鍙嶈浆 Hibernate Template鍜?Callback銆?
缁ф壙 HibernateDAOSupport鎻愪緵涓€涓狝OP 鎷︽埅鍣ㄣ€?/p>Spring鏀寔鐨凮RM
Spring鏀寔浠ヤ笅ORM锛?
Hibernate
iBatis
JPA (Java Persistence API)
TopLink
JDO (Java Data Objects)
OJB濡備綍閫氳繃HibernateDaoSupport灏哠pring鍜孒ibernate缁撳悎璧锋潵锛?
鐢⊿pring鐨?SessionFactory 璋冪敤 LocalSessionFactory銆傞泦鎴愯繃绋嬪垎涓夋锛?
閰嶇疆the Hibernate SessionFactory銆?
缁ф壙HibernateDaoSupport瀹炵幇涓€涓狣AO銆?
鍦ˋOP鏀寔鐨勪簨鍔′腑瑁呴厤銆?/p>Spring鏀寔鐨勪簨鍔$鐞嗙被鍨?
Spring鏀寔涓ょ绫诲瀷鐨勪簨鍔$鐞嗭細
缂栫▼寮忎簨鍔$鐞嗭細杩欐剰鍛充綘閫氳繃缂栫▼鐨勬柟寮忕鐞嗕簨鍔★紝缁欎綘甯︽潵鏋佸ぇ鐨勭伒娲绘€э紝浣嗘槸闅剧淮鎶ゃ€?
澹版槑寮忎簨鍔$鐞嗭細杩欐剰鍛崇潃浣犲彲浠ュ皢涓氬姟浠g爜鍜屼簨鍔$鐞嗗垎绂伙紝浣犲彧闇€鐢ㄦ敞瑙e拰XML閰嶇疆鏉ョ鐞嗕簨鍔°€?/p>Spring妗嗘灦鐨勪簨鍔$鐞嗘湁鍝簺浼樼偣锛?
瀹冧负涓嶅悓鐨勪簨鍔PI 濡?JTA锛孞DBC锛孒ibernate锛孞PA 鍜孞DO锛屾彁渚涗竴涓笉鍙樼殑缂栫▼妯″紡銆?
瀹冧负缂栫▼寮忎簨鍔$鐞嗘彁渚涗簡涓€濂楃畝鍗曠殑API鑰屼笉鏄竴浜涘鏉傜殑浜嬪姟API濡?
瀹冩敮鎸佸0鏄庡紡浜嬪姟绠$悊銆?
瀹冨拰Spring鍚勭鏁版嵁璁块棶鎶借薄灞傚緢濂藉緱闆嗘垚銆?/p>浣犳洿鍊惧悜鐢ㄩ偅绉嶄簨鍔$鐞嗙被鍨嬶紵
澶у鏁癝pring妗嗘灦鐨勭敤鎴烽€夋嫨澹版槑寮忎簨鍔$鐞嗭紝鍥犱负瀹冨搴旂敤浠g爜鐨勫奖鍝嶆渶灏忥紝鍥犳鏇寸鍚堜竴涓棤渚靛叆鐨勮交閲忕骇瀹瑰櫒鐨勬€濇兂銆傚0鏄庡紡浜嬪姟绠$悊瑕佷紭浜庣紪绋嬪紡浜嬪姟绠$悊锛岃櫧鐒舵瘮缂栫▼寮忎簨鍔$鐞嗭紙杩欑鏂瑰紡鍏佽浣犻€氳繃浠g爜鎺у埗浜嬪姟锛夊皯浜嗕竴鐐圭伒娲绘€с€?/p>
Spring闈㈠悜鍒囬潰缂栫▼锛圓OP锛?/h1>
瑙i噴AOP
闈㈠悜鍒囬潰鐨勭紪绋嬶紝鎴朅OP锛?鏄竴绉嶇紪绋嬫妧鏈紝鍏佽绋嬪簭妯″潡鍖栨í鍚戝垏鍓插叧娉ㄧ偣锛屾垨妯垏鍏稿瀷鐨勮矗浠诲垝鍒嗭紝濡傛棩蹇楀拰浜嬪姟绠$悊銆?/p>
Aspect 鍒囬潰
AOP鏍稿績灏辨槸鍒囬潰锛屽畠灏嗗涓被鐨勯€氱敤琛屼负灏佽鎴愬彲閲嶇敤鐨勬ā鍧楋紝璇ユā鍧楀惈鏈変竴缁凙PI鎻愪緵妯垏鍔熻兘銆傛瘮濡傦紝涓€涓棩蹇楁ā鍧楀彲浠ヨ绉颁綔鏃ュ織鐨凙OP鍒囬潰銆傛牴鎹渶姹傜殑涓嶅悓锛屼竴涓簲鐢ㄧ▼搴忓彲浠ユ湁鑻ュ共鍒囬潰銆傚湪Spring AOP涓紝鍒囬潰閫氳繃甯︽湁@Aspect娉ㄨВ鐨勭被瀹炵幇銆?/p>
鍦⊿pring AOP 涓紝鍏虫敞鐐瑰拰妯垏鍏虫敞鐨勫尯鍒槸浠€涔堬紵
鍏虫敞鐐规槸搴旂敤涓竴涓ā鍧楃殑琛屼负锛屼竴涓叧娉ㄧ偣鍙兘浼氳瀹氫箟鎴愪竴涓垜浠兂瀹炵幇鐨勪竴涓姛鑳姐€?
妯垏鍏虫敞鐐规槸涓€涓叧娉ㄧ偣锛屾鍏虫敞鐐规槸鏁翠釜搴旂敤閮戒細浣跨敤鐨勫姛鑳斤紝骞跺奖鍝嶆暣涓簲鐢紝姣斿鏃ュ織锛屽畨鍏ㄥ拰鏁版嵁浼犺緭锛屽嚑涔庡簲鐢ㄧ殑姣忎釜妯″潡閮介渶瑕佺殑鍔熻兘銆傚洜姝よ繖浜涢兘灞炰簬妯垏鍏虫敞鐐广€?/p>
杩炴帴鐐?
杩炴帴鐐逛唬琛ㄤ竴涓簲鐢ㄧ▼搴忕殑鏌愪釜浣嶇疆锛屽湪杩欎釜浣嶇疆鎴戜滑鍙互鎻掑叆涓€涓狝OP鍒囬潰锛屽畠瀹為檯涓婃槸涓簲鐢ㄧ▼搴忔墽琛孲pring AOP鐨勪綅缃€?/p>
閫氱煡
閫氱煡鏄釜鍦ㄦ柟娉曟墽琛屽墠鎴栨墽琛屽悗瑕佸仛鐨勫姩浣滐紝瀹為檯涓婃槸绋嬪簭鎵ц鏃惰閫氳繃SpringAOP妗嗘灦瑙﹀彂鐨勪唬鐮佹銆?
Spring鍒囬潰鍙互搴旂敤浜旂绫诲瀷鐨勯€氱煡锛?
before锛氬墠缃€氱煡锛屽湪涓€涓柟娉曟墽琛屽墠琚皟鐢ㄣ€?
after: 鍦ㄦ柟娉曟墽琛屼箣鍚庤皟鐢ㄧ殑閫氱煡锛屾棤璁烘柟娉曟墽琛屾槸鍚︽垚鍔熴€?
after-returning: 浠呭綋鏂规硶鎴愬姛瀹屾垚鍚庢墽琛岀殑閫氱煡銆?
after-throwing: 鍦ㄦ柟娉曟姏鍑哄紓甯搁€€鍑烘椂鎵ц鐨勯€氱煡銆?
around: 鍦ㄦ柟娉曟墽琛屼箣鍓嶅拰涔嬪悗璋冪敤鐨勯€氱煡銆?/p>
鍒囩偣
鍒囧叆鐐规槸涓€涓垨涓€缁勮繛鎺ョ偣锛岄€氱煡灏嗗湪杩欎簺浣嶇疆鎵ц銆傚彲浠ラ€氳繃琛ㄨ揪寮忔垨鍖归厤鐨勬柟寮忔寚鏄庡垏鍏ョ偣銆?/p>
浠€涔堟槸寮曞叆?
寮曞叆鍏佽鎴戜滑鍦ㄥ凡瀛樺湪鐨勭被涓鍔犳柊鐨勬柟娉曞拰灞炴€с€?/p>
浠€涔堟槸鐩爣瀵硅薄?
琚竴涓垨鑰呭涓垏闈㈡墍閫氱煡鐨勫璞°€傚畠閫氬父鏄竴涓唬鐞嗗璞°€備篃鎸囪閫氱煡锛坅dvised锛夊璞°€?/p>
浠€涔堟槸浠g悊?
浠g悊鏄€氱煡鐩爣瀵硅薄鍚庡垱寤虹殑瀵硅薄銆備粠瀹㈡埛绔殑瑙掑害鐪嬶紝浠g悊瀵硅薄鍜岀洰鏍囧璞℃槸涓€鏍风殑銆?/p>
鏈夊嚑绉嶄笉鍚岀被鍨嬬殑鑷姩浠g悊锛?
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
Metadata autoproxying
浠€涔堟槸缁囧叆銆備粈涔堟槸缁囧叆搴旂敤鐨勪笉鍚岀偣锛?
缁囧叆鏄皢鍒囬潰鍜屽埌鍏朵粬搴旂敤绫诲瀷鎴栧璞¤繛鎺ユ垨鍒涘缓涓€涓閫氱煡瀵硅薄鐨勮繃绋嬨€?
缁囧叆鍙互鍦ㄧ紪璇戞椂锛屽姞杞芥椂锛屾垨杩愯鏃跺畬鎴愩€?/p>
瑙i噴鍩轰簬XML Schema鏂瑰紡鐨勫垏闈㈠疄鐜般€?
鍦ㄨ繖绉嶆儏鍐典笅锛屽垏闈㈢敱甯歌绫讳互鍙婂熀浜嶺ML鐨勯厤缃疄鐜般€?/p>
瑙i噴鍩轰簬娉ㄨВ鐨勫垏闈㈠疄鐜?
鍦ㄨ繖绉嶆儏鍐典笅(鍩轰簬@AspectJ鐨勫疄鐜?锛屾秹鍙婂埌鐨勫垏闈㈠0鏄庣殑椋庢牸涓庡甫鏈塲ava5鏍囨敞鐨勬櫘閫歫ava绫讳竴鑷淬€?/p>
Spring 鐨凪VC
浠€涔堟槸Spring鐨凪VC妗嗘灦锛?
Spring 閰嶅鏋勫缓Web 搴旂敤鐨勫叏鍔熻兘MVC妗嗘灦銆係pring鍙互寰堜究鎹峰湴鍜屽叾浠朚VC妗嗘灦闆嗘垚锛屽Struts锛孲pring 鐨凪VC妗嗘灦鐢ㄦ帶鍒跺弽杞妸涓氬姟瀵硅薄鍜屾帶鍒堕€昏緫娓呮櫚鍦伴殧绂汇€傚畠涔熷厑璁镐互澹版槑鐨勬柟寮忔妸璇锋眰鍙傛暟鍜屼笟鍔″璞$粦瀹氥€?/p>
DispatcherServlet
Spring鐨凪VC妗嗘灦鏄洿缁旸ispatcherServlet鏉ヨ璁$殑锛屽畠鐢ㄦ潵澶勭悊鎵€鏈夌殑HTTP璇锋眰鍜屽搷搴斻€?/p>
WebApplicationContext
WebApplicationContext 缁ф壙浜咥pplicationContext 骞跺鍔犱簡涓€浜沇EB搴旂敤蹇呭鐨勭壒鏈夊姛鑳斤紝瀹冧笉鍚屼簬涓€鑸殑ApplicationContext 锛屽洜涓哄畠鑳藉鐞嗕富棰橈紝骞舵壘鍒拌鍏宠仈鐨剆ervlet銆?/p>
浠€涔堟槸Spring MVC妗嗘灦鐨勬帶鍒跺櫒锛?
鎺у埗鍣ㄦ彁渚涗竴涓闂簲鐢ㄧ▼搴忕殑琛屼负锛屾琛屼负閫氬父閫氳繃鏈嶅姟鎺ュ彛瀹炵幇銆傛帶鍒跺櫒瑙f瀽鐢ㄦ埛杈撳叆骞跺皢鍏惰浆鎹负涓€涓敱瑙嗗浘鍛堢幇缁欑敤鎴风殑妯″瀷銆係pring鐢ㄤ竴涓潪甯告娊璞$殑鏂瑰紡瀹炵幇浜嗕竴涓帶鍒跺眰锛屽厑璁哥敤鎴峰垱寤哄绉嶇敤閫旂殑鎺у埗鍣ㄣ€?/p>
@Controller 娉ㄨВ
璇ユ敞瑙h〃鏄庤绫绘壆婕旀帶鍒跺櫒鐨勮鑹诧紝Spring涓嶉渶瑕佷綘缁ф壙浠讳綍鍏朵粬鎺у埗鍣ㄥ熀绫绘垨寮曠敤Servlet API銆?/p>
@RequestMapping 娉ㄨВ
璇ユ敞瑙f槸鐢ㄦ潵鏄犲皠涓€涓猆RL鍒颁竴涓被鎴栦竴涓壒瀹氱殑澶勭悊鏂规硶涓娿€?/p>
瑙i噴AOP
闈㈠悜鍒囬潰鐨勭紪绋嬶紝鎴朅OP锛?鏄竴绉嶇紪绋嬫妧鏈紝鍏佽绋嬪簭妯″潡鍖栨í鍚戝垏鍓插叧娉ㄧ偣锛屾垨妯垏鍏稿瀷鐨勮矗浠诲垝鍒嗭紝濡傛棩蹇楀拰浜嬪姟绠$悊銆?/p>
Aspect 鍒囬潰
AOP鏍稿績灏辨槸鍒囬潰锛屽畠灏嗗涓被鐨勯€氱敤琛屼负灏佽鎴愬彲閲嶇敤鐨勬ā鍧楋紝璇ユā鍧楀惈鏈変竴缁凙PI鎻愪緵妯垏鍔熻兘銆傛瘮濡傦紝涓€涓棩蹇楁ā鍧楀彲浠ヨ绉颁綔鏃ュ織鐨凙OP鍒囬潰銆傛牴鎹渶姹傜殑涓嶅悓锛屼竴涓簲鐢ㄧ▼搴忓彲浠ユ湁鑻ュ共鍒囬潰銆傚湪Spring AOP涓紝鍒囬潰閫氳繃甯︽湁@Aspect娉ㄨВ鐨勭被瀹炵幇銆?/p>
鍦⊿pring AOP 涓紝鍏虫敞鐐瑰拰妯垏鍏虫敞鐨勫尯鍒槸浠€涔堬紵
鍏虫敞鐐规槸搴旂敤涓竴涓ā鍧楃殑琛屼负锛屼竴涓叧娉ㄧ偣鍙兘浼氳瀹氫箟鎴愪竴涓垜浠兂瀹炵幇鐨勪竴涓姛鑳姐€?
妯垏鍏虫敞鐐规槸涓€涓叧娉ㄧ偣锛屾鍏虫敞鐐规槸鏁翠釜搴旂敤閮戒細浣跨敤鐨勫姛鑳斤紝骞跺奖鍝嶆暣涓簲鐢紝姣斿鏃ュ織锛屽畨鍏ㄥ拰鏁版嵁浼犺緭锛屽嚑涔庡簲鐢ㄧ殑姣忎釜妯″潡閮介渶瑕佺殑鍔熻兘銆傚洜姝よ繖浜涢兘灞炰簬妯垏鍏虫敞鐐广€?/p>
杩炴帴鐐?
杩炴帴鐐逛唬琛ㄤ竴涓簲鐢ㄧ▼搴忕殑鏌愪釜浣嶇疆锛屽湪杩欎釜浣嶇疆鎴戜滑鍙互鎻掑叆涓€涓狝OP鍒囬潰锛屽畠瀹為檯涓婃槸涓簲鐢ㄧ▼搴忔墽琛孲pring AOP鐨勪綅缃€?/p>
閫氱煡
閫氱煡鏄釜鍦ㄦ柟娉曟墽琛屽墠鎴栨墽琛屽悗瑕佸仛鐨勫姩浣滐紝瀹為檯涓婃槸绋嬪簭鎵ц鏃惰閫氳繃SpringAOP妗嗘灦瑙﹀彂鐨勪唬鐮佹銆?
Spring鍒囬潰鍙互搴旂敤浜旂绫诲瀷鐨勯€氱煡锛?
before锛氬墠缃€氱煡锛屽湪涓€涓柟娉曟墽琛屽墠琚皟鐢ㄣ€?
after: 鍦ㄦ柟娉曟墽琛屼箣鍚庤皟鐢ㄧ殑閫氱煡锛屾棤璁烘柟娉曟墽琛屾槸鍚︽垚鍔熴€?
after-returning: 浠呭綋鏂规硶鎴愬姛瀹屾垚鍚庢墽琛岀殑閫氱煡銆?
after-throwing: 鍦ㄦ柟娉曟姏鍑哄紓甯搁€€鍑烘椂鎵ц鐨勯€氱煡銆?
around: 鍦ㄦ柟娉曟墽琛屼箣鍓嶅拰涔嬪悗璋冪敤鐨勯€氱煡銆?/p>
鍒囩偣
鍒囧叆鐐规槸涓€涓垨涓€缁勮繛鎺ョ偣锛岄€氱煡灏嗗湪杩欎簺浣嶇疆鎵ц銆傚彲浠ラ€氳繃琛ㄨ揪寮忔垨鍖归厤鐨勬柟寮忔寚鏄庡垏鍏ョ偣銆?/p>
浠€涔堟槸寮曞叆?
寮曞叆鍏佽鎴戜滑鍦ㄥ凡瀛樺湪鐨勭被涓鍔犳柊鐨勬柟娉曞拰灞炴€с€?/p>
浠€涔堟槸鐩爣瀵硅薄?
琚竴涓垨鑰呭涓垏闈㈡墍閫氱煡鐨勫璞°€傚畠閫氬父鏄竴涓唬鐞嗗璞°€備篃鎸囪閫氱煡锛坅dvised锛夊璞°€?/p>
浠€涔堟槸浠g悊?
浠g悊鏄€氱煡鐩爣瀵硅薄鍚庡垱寤虹殑瀵硅薄銆備粠瀹㈡埛绔殑瑙掑害鐪嬶紝浠g悊瀵硅薄鍜岀洰鏍囧璞℃槸涓€鏍风殑銆?/p>
鏈夊嚑绉嶄笉鍚岀被鍨嬬殑鑷姩浠g悊锛?
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
Metadata autoproxying
浠€涔堟槸缁囧叆銆備粈涔堟槸缁囧叆搴旂敤鐨勪笉鍚岀偣锛?
缁囧叆鏄皢鍒囬潰鍜屽埌鍏朵粬搴旂敤绫诲瀷鎴栧璞¤繛鎺ユ垨鍒涘缓涓€涓閫氱煡瀵硅薄鐨勮繃绋嬨€?
缁囧叆鍙互鍦ㄧ紪璇戞椂锛屽姞杞芥椂锛屾垨杩愯鏃跺畬鎴愩€?/p>
瑙i噴鍩轰簬XML Schema鏂瑰紡鐨勫垏闈㈠疄鐜般€?
鍦ㄨ繖绉嶆儏鍐典笅锛屽垏闈㈢敱甯歌绫讳互鍙婂熀浜嶺ML鐨勯厤缃疄鐜般€?/p>
瑙i噴鍩轰簬娉ㄨВ鐨勫垏闈㈠疄鐜?
鍦ㄨ繖绉嶆儏鍐典笅(鍩轰簬@AspectJ鐨勫疄鐜?锛屾秹鍙婂埌鐨勫垏闈㈠0鏄庣殑椋庢牸涓庡甫鏈塲ava5鏍囨敞鐨勬櫘閫歫ava绫讳竴鑷淬€?/p>
浠€涔堟槸Spring鐨凪VC妗嗘灦锛?
Spring 閰嶅鏋勫缓Web 搴旂敤鐨勫叏鍔熻兘MVC妗嗘灦銆係pring鍙互寰堜究鎹峰湴鍜屽叾浠朚VC妗嗘灦闆嗘垚锛屽Struts锛孲pring 鐨凪VC妗嗘灦鐢ㄦ帶鍒跺弽杞妸涓氬姟瀵硅薄鍜屾帶鍒堕€昏緫娓呮櫚鍦伴殧绂汇€傚畠涔熷厑璁镐互澹版槑鐨勬柟寮忔妸璇锋眰鍙傛暟鍜屼笟鍔″璞$粦瀹氥€?/p>
DispatcherServlet
Spring鐨凪VC妗嗘灦鏄洿缁旸ispatcherServlet鏉ヨ璁$殑锛屽畠鐢ㄦ潵澶勭悊鎵€鏈夌殑HTTP璇锋眰鍜屽搷搴斻€?/p>
WebApplicationContext
WebApplicationContext 缁ф壙浜咥pplicationContext 骞跺鍔犱簡涓€浜沇EB搴旂敤蹇呭鐨勭壒鏈夊姛鑳斤紝瀹冧笉鍚屼簬涓€鑸殑ApplicationContext 锛屽洜涓哄畠鑳藉鐞嗕富棰橈紝骞舵壘鍒拌鍏宠仈鐨剆ervlet銆?/p>
浠€涔堟槸Spring MVC妗嗘灦鐨勬帶鍒跺櫒锛?
鎺у埗鍣ㄦ彁渚涗竴涓闂簲鐢ㄧ▼搴忕殑琛屼负锛屾琛屼负閫氬父閫氳繃鏈嶅姟鎺ュ彛瀹炵幇銆傛帶鍒跺櫒瑙f瀽鐢ㄦ埛杈撳叆骞跺皢鍏惰浆鎹负涓€涓敱瑙嗗浘鍛堢幇缁欑敤鎴风殑妯″瀷銆係pring鐢ㄤ竴涓潪甯告娊璞$殑鏂瑰紡瀹炵幇浜嗕竴涓帶鍒跺眰锛屽厑璁哥敤鎴峰垱寤哄绉嶇敤閫旂殑鎺у埗鍣ㄣ€?/p>
@Controller 娉ㄨВ
璇ユ敞瑙h〃鏄庤绫绘壆婕旀帶鍒跺櫒鐨勮鑹诧紝Spring涓嶉渶瑕佷綘缁ф壙浠讳綍鍏朵粬鎺у埗鍣ㄥ熀绫绘垨寮曠敤Servlet API銆?/p>
@RequestMapping 娉ㄨВ
璇ユ敞瑙f槸鐢ㄦ潵鏄犲皠涓€涓猆RL鍒颁竴涓被鎴栦竴涓壒瀹氱殑澶勭悊鏂规硶涓娿€?/p>
以上是关于69閬揝pring闈㈣瘯棰樺拰绛旀的主要内容,如果未能解决你的问题,请参考以下文章