标签:app div ati stat port out 模式 static dem
package com.etc.pojo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpUtil { static private ApplicationContext ac; static { ac = new ClassPathXmlApplicationContext("applicationContext.xml"); } private SpUtil() { } public static ApplicationContext getAc() { return ac; } }
package com.etc.test; import org.junit.Test; import org.springframework.context.ApplicationContext; import com.etc.pojo.SpUtil; public class TestDemo { @Test public void test05() { //实现方式四 单例模式 ApplicationContext ac = SpUtil.getAc(); System.out.println(ac.getBean("person")); } }
Spring加载applicationContext.xml实现spring容器管理的单例模式
标签:app div ati stat port out 模式 static dem
原文地址:http://www.cnblogs.com/1020182600HENG/p/6900108.html