文章詳情頁
Spring獲取ApplicationContext對象工具類的實(shí)現(xiàn)方法
瀏覽:123日期:2022-06-07 08:38:58
Spring獲取ApplicationContext對象工具類的實(shí)現(xiàn)方法
(1)實(shí)現(xiàn)的工具類:
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"); }
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
標(biāo)簽:
JSP
相關(guān)文章:
1. Java Spring WEB應(yīng)用實(shí)例化如何實(shí)現(xiàn)2. 基于spring三方包類注入容器的四種方式小結(jié)3. 通過工廠模式返回Spring Bean方法解析4. Spring 框架簡介5. SpringMVC生成的驗(yàn)證碼圖片不顯示問題及解決方法6. Spring boot集成Kafka消息中間件代碼實(shí)例7. 使用SpringBoot自定義starter詳解8. 解決springboot的aop切面不起作用問題(失效的排查)9. SpringBoot+Shiro+LayUI權(quán)限管理系統(tǒng)項(xiàng)目源碼10. spring boot+ redis 接口訪問頻率限制的實(shí)現(xiàn)
排行榜
