文章詳情頁
Spring獲取ApplicationContext對象工具類的實現方法
瀏覽:379日期: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使用Mybatis-Generator配置過程詳解2. SpringBoot整合Dubbo框架,實現RPC服務遠程調用3. Spring Boot使用JSR-380進行校驗的示例4. Springboot使用thymeleaf動態模板實現刷新5. 淺談SpringMVC jsp前臺獲取參數的方式 EL表達式6. SpringBoot攔截器原理解析及使用方法7. Springboot實現XSS漏洞過濾的示例代碼8. 一篇文章帶你搞定SpringBoot中的熱部署devtools方法9. SpringBoot 開發提速神器 Lombok+MybatisPlus+SwaggerUI10. springboot 使用yml配置文件給靜態變量賦值教程
排行榜