web欏圭洰涓?
絎竴姝ワ細鍐欎竴涓被ThtApplicationContext瀹炵幇 Spring 鐨勬帴鍙?org.springframework.context.ApplicationContext
騫跺疄鐜板畠鐨勬柟娉?/span>
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
//1 this.applicationContext = arg0;
}
絎簩姝ワ細鍦ㄧ被涓畾涔?nbsp; org.springframework.context.ApplicationContext綾誨瀷鐨勫睘鎬?/span>
濡傦細private static ApplicationContext applicationContext;
鍚屾椂鍦ㄧ涓姝ヤ腑灝哸rg0璧嬬粰applicationContext;鍗崇涓姝ヤ腑琚敞閲婄殑1
鑷充簬闈欐佺殑鏂規(guī)硶:涓轟簡浠ュ悗澶氭浣跨敤鏃訛紝灝辯敤涓涓狝pplicationContext瀵硅薄灝卞彲浠ヤ簡錛岃妭璧勬簮
絎笁姝ワ細
鍙戝竷鏂規(guī)硶錛氫緵澶栭儴浣跨敤錛岃繑鍥炲間負錛歰rg.springframework.context.ApplicationContext
public static ApplicationContext getApplicationContext(){
return applicationContext;
}
絎洓姝ワ細鍦⊿pring閰嶇疆鏂囦歡涓厤
<bean class="...ThtApplicationContext瀹為檯璺緞" />
鍦ㄥ惎鍔╓eb欏圭洰鏃跺姞杞絊pring閰嶇疆鏂囦歡鏃訛紝Spring鎶妎rg.springframework.context.ApplicationContext浣滀負灞炴ф敞鍏ョ粰綾?ThtApplicationContext
絎簲姝ワ細鏅氱被涓嬌鐢細
Object obj=ThtApplicationContext.getApplicationContext().getBean("BeanName");
obj 閲岃竟鏀劇殑灝辨槸spring涓?bean閰嶇疆鐨勭被瀵硅薄浜?/span>
OK,鎴愬姛銆?br />