文章詳情頁
Spring獲取ApplicationContext對象工具類的實(shí)現(xiàn)方法
瀏覽:434日期: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. 使用Maven 搭建 Spring MVC 本地部署Tomcat的詳細(xì)教程2. 通過IEAD+Maven快速搭建SSM項(xiàng)目的過程(Spring + Spring MVC + Mybatis)3. 使用Spring自定義實(shí)現(xiàn)IOC和依賴注入(注解方式)4. 解決SpringBoot中使用@Async注解失效的問題5. spring 中事務(wù)注解@Transactional與trycatch的使用6. SpringBoot參數(shù)校驗(yàn)與國際化使用教程7. Admin - SpringBoot + Maven 多啟動環(huán)境配置實(shí)例詳解8. SpringBoot獲取Request和Response方法代碼解析9. Spring MVC+ajax進(jìn)行信息驗(yàn)證的方法10. SpringBoot整合Redis的步驟
排行榜

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