文章詳情頁
Spring獲取ApplicationContext對(duì)象工具類的實(shí)現(xiàn)方法
瀏覽:150日期:2022-06-07 08:38:58
Spring獲取ApplicationContext對(duì)象工具類的實(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(){ //獲得返回的容器對(duì)象 return ac; } }
(2)使用方法:
public static void getByUtil(){ ApplicationContextUtil.getApplicationContext().getBean("userService"); }
如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
標(biāo)簽:
JSP
相關(guān)文章:
1. 使用SpringBoot AOP 記錄操作日志、異常日志的過程2. springboot 啟動(dòng)如何排除某些bean的注入3. SpringBoot配置shiro安全框架的實(shí)現(xiàn)4. springboot用controller跳轉(zhuǎn)html頁面的實(shí)現(xiàn)5. SpringBoot 改造成https訪問的實(shí)現(xiàn)6. spring boot使用@Async異步注解的實(shí)現(xiàn)原理+源碼7. @PathVariable注解,讓spring支持參數(shù)帶值功能的案例8. SpringBoot+VUE實(shí)現(xiàn)數(shù)據(jù)表格的實(shí)戰(zhàn)9. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟10. springboot如何使用@ConfigurationProperties封裝配置文件
排行榜
