Spring IOC实例化了哪些对象

[size=x-large][b][color=red][align=center]Spring IOC实例化了哪些对象[/align][/color][/b][/size]


启动servlet容器(tomcat),加载web.xml-->加载applicationContext.xml
spring的配置文件[color=red]applicationContext.xml[/color]大致如下:

   
//将beanService对象注入到Action对象 也可以用注解@Resource beanService
<bean id="Login" class="sshdemo.func001.action.LoginAction" scope="prototype">
<property name="personService" ref="personService" />
</bean>

//将Dao对象注入到beanService对象里面
<bean id="personService" class="sshdemo.func001.service.PersonServiceImpl">
<property name="personDAO" ref="PersonDAO" />
</bean>

//将HibernateTemplate注入到Dao对象里面
<bean id="PersonDAO" class="sshdemo.func001.dao.PersonDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

//将DB连接设置到SessionFactory 也可以通过加载hibernate.cfg.xml创建SessionFactory对象
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>

//创建DB连接,也可以通过配置文件hibernate.cfg.xml里配置参数
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
</bean>



然后在启动tomcat之后,还没有运行程序前,自己配置的log4j打出的日志有如下:
---------------------------------日志分割线--------------------------------------
Loaded 6 bean definitions from location pattern [[color=red]/WEB-INF/applicationContext.xml[/color]]
。。。
6 beans defined in org.springframework.web.context.support.XmlWebApplicationContext@179dce4: display name ; 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 [[color=red]Login,personService,PersonDAO,sessionFactory,dataSource,ChartAction[/color]]; 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里面去。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值