文章詳情頁
Spring獲取ApplicationContext對象工具類的實現方法
瀏覽:153日期: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. SpringBoot的WebSocket實現單聊群聊2. springboot+websocket+redis搭建的實現3. SpringBoot整合log4j日志與HashMap的底層原理解析4. SpringBoot 啟動方法run()源碼解析5. SpringBoot+JavaMailSender實現騰訊企業郵箱配置6. Springboot WebFlux集成Spring Security實現JWT認證的示例7. SpringBoot+TestNG單元測試的實現8. 詳解如何為SpringBoot項目中的自定義配置添加IDE支持9. springboot 中 druid+jpa+MYSQL數據庫配置過程10. SpringBoot生成二維碼的實現
排行榜
