spring原理
2015-09-10 18:02
555 查看
1、spring框架什么时候被加载?
(1)ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml")执行的时候,
spring容器对象被创建。
(2)同时,applicationContext.xml里面配置的对象被创建到内存中。(内存模型类似于HashMap)。容器利用反射机制创建bean的实例。如下图
View Code
(1)ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml")执行的时候,
spring容器对象被创建。
(2)同时,applicationContext.xml里面配置的对象被创建到内存中。(内存模型类似于HashMap)。容器利用反射机制创建bean的实例。如下图
package com.run; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.spring.service.SpringService; public class Run { public static void testRun(){ //1、创建spring的IOC容器对象 @SuppressWarnings("resource") ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext-bean.xml"); //2、从IOC容器获取spring bean实例 //SpringService sService = (SpringService)ac.getBean("springService"); SpringService sService = (SpringService)ac.getBean(SpringService.class); //3、调用sayHello方法 sService.sayHello(); } public static void main(String[] args) { testRun(); } }
View Code
相关文章推荐
- Java的ArrayList源码浅析
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- java验证一个数是2的次幂
- Java CheckException与UncheckException
- spring容器创建对象的生命周期
- 【Spring】Spring MVC 的json问题(406 Not Acceptable)
- Maven Struts2
- struts2的获取请求方法
- Java访问权限修饰词
- java中thread的start()和run()的区别
- Java 集合 使用contains方法
- JAVA线程
- 初识 Struts1.x
- 关于JAVA IO流中拷贝文件的几种方法
- Eclipse下svn的创建分支/合并/切换使用
- Java中getResourceAsStream的用法
- java文件上传到服务器
- Spring MVC在接收复杂集合参数
- Struts2常用标签总结
- Java中Runnable和Thread的区别