spring_6ssh整合

spring整合Hibernate

整合目标

1.由spring的Ioc容器生成hibernate的SessionFactory
2.让hibernate使用spring的声明式事务

spring整合Hibernate步骤

1).先加入hibernate
①. jar包
②. 添加hibernate的配置文件hibernate.cfg.xml,并写相应配置
③. 编写持久化类对应的 .hbm.xml文件
2).再加入Spring
①. jar包
②. 加入spring的配置文件,并进行配置
配置数据源,并测试数据源getConnection()方法
配置Hibernate的SessionFactory实例,测试数据源getConnection()会创建数据表
配置Spring的声明式事务
3).整合

spring整合Struts2

整合目标

使 IOC 容器来管理 Struts2 的 Action。
在spring配置文件中装配action类的bean,struts.xml中配置action的class属性指向bean的id。

spring如何进行整合struts2 ?

1.加入所需的jar包
2.写好相应的业务层代码和jsp页面
3.配置web.xml在原来的基础上加入的配置

  <!-- 配置spring配置文件的名称和位置 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!-- 启动Ioc容器的ServletContextListener -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>  

4.配置spring的配置文件applicationContext.xml
把action类放入Ioc容器中

    <!-- 注意:在Ioc容器中配置Struts2的Action时,需要配置scope属性必须为prototype,即struts中action是非单例的 -->
    <bean id="personAction" 
        class="action.PersonAction" 
        scope="prototype">
        <property name="personService" ref="personServie"></property>
    </bean>  

5.配置struts.xml文件
action的class属性指向Ioc容器中的action类的bean的id

posted @ 2016-05-07 16:54  Taogen  阅读(162)  评论(0编辑  收藏  举报