Spring 容器初始化方法
2015-10-14 22:37
501 查看
Resource resource = new ClassPathResource("/bean.xml");
resource = new FileSystemResource("d:/tzspring02/src/bean.xml");
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
/*spring容器加载资源文件的核心类 PathMatchingResourcePatternResolver*/
ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
Resource resource = resourceLoader.getResource("classpath:bean.xml");//ClassPathResource
System.out.println(resource.getDescription()+"===="+resource.getFile().getAbsolutePath());
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
System.out.println("########1");
ApplicationContext application1 = new ClassPathXmlApplicationContext("classpath:/com/easeye/conf/applicationContext.xml");
Student stu1 = application1.getBean("student",Student.class);
stu1.ShowInfo();
System.out.println("########2");
ApplicationContext application2 = new FileSystemXmlApplicationContext("file:D:/Software/apache-tomcat-7.0.59/webapps/SpringDemo/WEB-INF/classes/com/easeye/conf/applicationContext.xml");
Student stu2 = application2.getBean("student",Student.class);
stu2.ShowInfo();
System.out.println("########3");
ApplicationContext application3 = new AnnotationConfigApplicationContext("com.easeye.test");
Student stu3 = application3.getBean("student",Student.class);
stu2.ShowInfo();
resource = new FileSystemResource("d:/tzspring02/src/bean.xml");
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
/*spring容器加载资源文件的核心类 PathMatchingResourcePatternResolver*/
ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
Resource resource = resourceLoader.getResource("classpath:bean.xml");//ClassPathResource
System.out.println(resource.getDescription()+"===="+resource.getFile().getAbsolutePath());
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
System.out.println("########1");
ApplicationContext application1 = new ClassPathXmlApplicationContext("classpath:/com/easeye/conf/applicationContext.xml");
Student stu1 = application1.getBean("student",Student.class);
stu1.ShowInfo();
System.out.println("########2");
ApplicationContext application2 = new FileSystemXmlApplicationContext("file:D:/Software/apache-tomcat-7.0.59/webapps/SpringDemo/WEB-INF/classes/com/easeye/conf/applicationContext.xml");
Student stu2 = application2.getBean("student",Student.class);
stu2.ShowInfo();
System.out.println("########3");
ApplicationContext application3 = new AnnotationConfigApplicationContext("com.easeye.test");
Student stu3 = application3.getBean("student",Student.class);
stu2.ShowInfo();
相关文章推荐
- java缓存技术
- java判断一个字符串是否为空的方法总结
- 学习心得(Java语言)
- Java从入门到精通14-GridLayout网格布局
- springMVC的HandlerInterceptor拦截器
- 关于java中有符号数转换成无符号数的相关问题
- Java从入门到精通13-FlowLayout布局
- 抽象工厂模式(java语言实现)
- 《深入理解java虚拟机》之内存模型与安全
- Java内存泄露监控工具__JVM监控工具介绍
- 转换java keytools的keystore证书到OPENSSL的PEM格式文件
- java锁机制
- Eclipse操作技巧
- MyEclipse 查看JDK类库的源代码
- Eclipse的基本使用
- Android成长笔记(1)——Windows+eclipse+Android开发环境搭建
- Java剪切板操作大全
- 交换排序——快速排序
- Java进程监控与分析
- 排序算法之直接插入排序(java实现)