import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
* 实例化容器测试类
* */
public class Test {
public static void main(String[] args){
//方式一:在CLASSPATH路径下获取XMLBeanFactory实例
ClassPathResource res = new ClassPathResource("container.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);
HelloBean hellobean = (HelloBean)factory.getBean("helloBean");
hellobean.sayHelloWorld();

//方式二:指定绝对路径建ApplicatinContext实例
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("D:\\My_Struts_Cvs8\\springioc\\src\\container.xml");
BeanFactory factory2 = (BeanFactory) context;
HelloBean hellobean2 = (HelloBean)factory2.getBean("helloBean");
hellobean2.sayHelloWorld();

//方式三:通过ClassPathXmlApplicationContext创建BeanFactory实例
ClassPathXmlApplicationContext context3 = new ClassPathXmlApplicationContext("container.xml");
BeanFactory factory3 = (BeanFactory) context3;
HelloBean hellobean3 = (HelloBean)factory3.getBean("helloBean");
hellobean3.sayHelloWorld();
}

最新文章

  1. Hibernate 错题分析
  2. 如何使用ArcGIS Online的地图数据作为底图
  3. mysql查询语句中用户变量的使用
  4. TopShelf&Quartz.Net实现多任务的值守
  5. Effective Java 36 Consistently use the Override annotation
  6. git一些常用设置
  7. CRM 2016 自动保存 Save event arguments
  8. C++ Code_animateCtrl
  9. Properties 转换成Map
  10. POJ 2481 Cows
  11. SQL开发中容易忽视的一些小地方(六)
  12. iOS UICollectionView 长按移动cell
  13. MPSOC之6——开发流程linux编译
  14. instrument(2)
  15. 针对特定网站scrapy爬虫的性能优化
  16. Fiddler抓包2-只抓APP的请求
  17. dependencies与dependencyManagement的区别
  18. python---九九乘法表代码
  19. win7下安装curl
  20. 2D旋转和3D旋转

热门文章

  1. kvm iptables 3306端口
  2. Android Tombstone 分析
  3. 北京儿研所自制药一览表,宝妈们必读!<转>
  4. Android 图片相关
  5. android task stack
  6. 【总结整理】关于ArcGIS中拓扑的理解
  7. EZOJ #73
  8. Luogu 3911 最小公倍数之和
  9. SSH框架(四) struts2+spring3.0的登陆示例
  10. DBUtils工具类和DBCP连接池