Spring獲取ApplicationContext對象工具類的實現方法,大家都了解嗎?其實Spring都是高級的容器,這個時候我們要把ApplicationContext設置進去哦,別著急,下面就讓錯新技術頻道小編帶大家學習吧!
?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"); } 上述就是錯新技術頻道小編帶給大家帶來的Spring獲取ApplicationContext對象工具類的實現方法,大家可以收藏本文,方便大家的使用。
新聞熱點
疑難解答