《SSH框架》---spring

一、简介:

   spring框架,是进行对象管理,对象关联,解耦的一个中间层框架。SSHStruts+Spring+hibernate)三大Spring在中间就起着一个承上启下的作用。

   Spring是一个轻量级的IOCAOP容器框架:

   1、轻量级:程序实现不是很复杂,代码不是很多,占用资源不是很多,没有侵入性;

   2IOCInversion ofControl 控制反转):对象创建责任的反转(重点,核心);

   3Aop(AspectOriented Programming):一种面向横切面编程的思想方式,可以进行功能性扩展,看前边的一篇转载的博客:面向横切面(AOP)编程。

   4、容器:可以容纳对象,并且可以控制对象的生命周期;

   (因为这些概念,在这次的ssh中没有很深的体会,所以就不细致讲解了)


二、配置过程:

     

1、引入Sprign jar包:


Spring3.2 开发最基本jar

spring-beans-3.2.0.RELEASE.jar

spring-context-3.2.0.RELEASE.jar

spring-core-3.2.0.RELEASE.jar

spring-expression-3.2.0.RELEASE.jar

com.springsource.org.apache.commons.logging-1.1.1.jar

com.springsource.org.apache.log4j-1.2.15.jar

AOP开发

spring-aop-3.2.0.RELEASE.jar

spring-aspects-3.2.0.RELEASE.jar

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

Spring Jdbc开发

spring-jdbc-3.2.0.RELEASE.jar

spring-tx-3.2.0.RELEASE.jar

Spring事务管理

spring-tx-3.2.0.RELEASE.jar

Spring整合其他ORM框架

spring-orm-3.2.0.RELEASE.jar

Springweb中使用

spring-web-3.2.0.RELEASE.jar

Spring整合Junit测试

spring-test-3.2.0.RELEASE.jar

2、编写核心配置文件:

* 引入applicationContext.xml(框架的核心配置文件)到SRC中:


      

     *Web.xml---配置核心监听器:  

<!-- 配置Spring的核心监听器 -->
 <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
 </context-param>

     * 引入log4j.properties(控制log4j的日志输出基本,输出目的地以及输出格式)

3、在Spring对象中声明和初始化对象:

   ***********************以后台商品管理为例*******************************

 

    <!-- 后台商品管理的Action -->
<beanid="adminProductAction"class="cn.itcast.shop.product.adminaction.AdminProductAction"scope="prototype">
<propertyname="productService" ref="productService"/>
</bean>
 
   <!-- 后台商品管理的Service -->
     <beanid="productService"class="cn.itcast.shop.product.service.ProductService">
<propertyname="productDao" ref="productDao"/>
</bean>
    <!-- 后台商品管理的Dao -->
    <beanid="productDao"class="cn.itcast.shop.product.dao.ProductDao">
<propertyname="sessionFactory" ref="sessionFactory"/>
</bean> 

 分析:

1、框架创建对象的方式:

   框架默认创建对象是单例的:scope="singleton"

   当然action我们想要多例创建,需要设置:scope="prototype"

2、工厂BeanFactory,如果使用BeanFactory来加载Spring配置文件,那么是在调用getBean时,框架调用对象的默认构造方法来创建对象。BeanFactory功能是对bean对象的生命周期进行管理的。(创建,初始化,销毁)。

3ApplicationContext(推荐,也是框架默认的)(百度到的,我也不是很理解)

    对象来加载Spring配置文件,会在加载时解析配置文件,创建对象,而不是在getBean时创建。其实,ApplicationContext接口继承了BeanFactory,所以具备BeanFactory所有功能,同时增加扩展的功能,例如加载资源配置文件,国际化支持等!

三、最后

    单看spring,并没感觉有多么吸引人,但是结合到其他的框架,它的优势就显示出来了。在上一篇博客中,我们讲到了springStruts结合,既然spring起到承上启下的作用,那么它必定还会和hibernate进行结合,请关注下一篇博客《SSH框架》--Hibernate。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 25
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小王师傅66

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值