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"));
	}
}

  

相关文章:

  • 2021-11-19
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-11-19
  • 2022-02-27
  • 2021-07-18
猜你喜欢
  • 2022-12-23
  • 2021-05-20
  • 2021-07-23
  • 2021-11-19
  • 2021-11-20
  • 2021-05-16
  • 2022-12-23
相关资源
相似解决方案