文章詳情頁
Spring獲取ApplicationContext對象工具類的實現方法
瀏覽:163日期: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自定義XML schema 擴展的問題(Spring面試高頻題)2. SpringBoot實現devtools實現熱部署過程解析3. 基于 SpringBoot 實現 MySQL 讀寫分離的問題4. SpringBoot 開發提速神器 Lombok+MybatisPlus+SwaggerUI5. springboot整合Shiro的步驟6. springboot多模塊包掃描問題的解決方法7. 詳解MySQL與Spring的自動提交(autocommit)8. 關于Spring AOP使用時的一些問題匯總9. springboot CommandLineRunner接口實現自動任務加載功能10. 關于使用IDEA的springboot框架往Redis里寫入數據亂碼問題
排行榜