文章詳情頁
Spring獲取ApplicationContext對象工具類的實現方法
瀏覽:417日期:2022-06-07 08:38:58
Spring獲取ApplicationContext對象工具類的實現方法
(1)實現的工具類:
package com.util;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
final public class ApplicationContextUtil {
private static ApplicationContext ac=null;
private ApplicationContextUtil(){
}
static{
ac=new ClassPathXmlApplicationContext("applicationContext.xml");
}
public static ApplicationContext getApplicationContext(){
//獲得返回的容器對象
return ac;
}
}
(2)使用方法:
public static void getByUtil(){
ApplicationContextUtil.getApplicationContext().getBean("userService");
}
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
標簽:
JSP
相關文章:
1. Spring Boot和Thymeleaf整合結合JPA實現分頁效果(實例代碼)2. Springboot Druid 自定義加密數據庫密碼的幾種方案3. Spring MVC+ajax進行信息驗證的方法4. spring acegi security 1.0.0 發布5. Spring Boot 整合 Apache Dubbo的示例代碼6. SpringBoot結合ProGuard實現代碼混淆(最新版)7. Spring Boot使用JSR-380進行校驗的示例8. SpringBoot中定制異常頁面的實現方法9. Spring Boot應用上傳文件時報錯的原因及解決方案10. Springboot 如何實現filter攔截token驗證和跨域
排行榜

網公網安備