文章詳情頁(yè)
Spring獲取ApplicationContext對(duì)象工具類的實(shí)現(xiàn)方法
瀏覽:394日期: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. Spring如何集成ibatis項(xiàng)目并實(shí)現(xiàn)dao層基類封裝2. Spring Boot 功能整合的實(shí)現(xiàn)3. Spring中@Value讀取properties作為map或list的操作4. 關(guān)于Spring自定義XML schema 擴(kuò)展的問題(Spring面試高頻題)5. SpringBoot集成Redisson實(shí)現(xiàn)延遲隊(duì)列的場(chǎng)景分析6. Spring計(jì)時(shí)器StopWatch使用示例7. SpringMVC+Jquery實(shí)現(xiàn)Ajax功能8. SpringBoot配置shiro安全框架的實(shí)現(xiàn)9. springboot bootcdn使用示例詳解10. SpringBoot應(yīng)用整合ELK實(shí)現(xiàn)日志收集的示例代碼
排行榜

網(wǎng)公網(wǎng)安備