Spring IOC实例化了哪些对象
Spring IOC实例化了哪些对象
启动servlet容器(tomcat),加载web.xml-->加载applicationContext.xml
spring的配置文件applicationContext.xml大致如下:
然后在启动tomcat之后,还没有运行程序前,自己配置的log4j打出的日志有如下:
---------------------------------日志分割线--------------------------------------
Loaded 6 bean definitions from location pattern [/WEB-INF/applicationContext.xml]
。。。
6 beans defined in org.springframework.web.context.support.XmlWebApplicationContext@179dce4: display name [Root WebApplicationContext]; startup date [Thu May 14 08:44:00 CST 2009]; root of context hierarchy
。。。
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6210fb: defining beans [Login,personService,PersonDAO,sessionFactory,dataSource,ChartAction]; root of factory hierarchy
Creating shared instance of singleton bean 'personService'
Creating instance of bean 'personService'
Eagerly caching bean 'personService' to allow for resolving potential circular references
Creating shared instance of singleton bean 'PersonDAO'
Creating instance of bean 'PersonDAO'
Eagerly caching bean 'PersonDAO' to allow for resolving potential circular references
Creating shared instance of singleton bean 'sessionFactory'
Creating instance of bean 'sessionFactory'
Eagerly caching bean 'sessionFactory' to allow for resolving potential circular references
Creating shared instance of singleton bean 'dataSource'
Creating instance of bean 'dataSource'
Eagerly caching bean 'dataSource' to allow for resolving potential circular references
。。。
---------------------------------日志分割线--------------------------------------
在启动servlet容器(tomcat)时,
1.spring就已经初始化了action,PersonServiceImpl,PersonDAOImpl,sessionFactory,dataSource
2.struts2的具体action实例也实例化,但是没包装数据,当用户访问*.action时,会把jsp页面里面的参数包装设置到action的属性里面。这里与struts 1.x不同之处:struts是*.do,经过web.xml过滤,查找有没有请求的action,有--->通过struts-config.xml-->找到<action../>-->对应的beanForm-->把请求参数设置到beanForm里面去。