SSH三大框架简单整合

SSH整合:我写的整合方式是xml配合注解的整合方式,按程序流程整合。


(一)导入jar包:导入SSH整合的基本jar包

(二)服务器启动:加载web.xml 

在web.xml中配置Struts2的核心入口(核心过滤器) 

       配置 Spring创建ApplicationContext的监听器       ContextLoaderListener位于spring-web的jar包中

                                                               配置全局参数,监听器获取applicationContext.xml的路径,为了让ApplicationContext对象加载spring配置文件。


(三)配置applicationContext.xml:导入spring配置文件的约束   引入hibernate配置信息

1、导入约束

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">
</beans>

         2、开启包扫描器和事务对注解的支持

      3、配置数据源(连接池)我这里配置的c3p0连接池


    4、配置hibernate配置信息:hibernate和spring的整合就是将sessionFactory的创建权交给spring 由spring管理sessionFactory 这里利用spring框架的hiernate模板中的一个LocalSessionFactoryBean类,对sessionFactory进行封装。(具体的一些封装细节和session封装细节,以后我会慢慢写出来)

一个要注意的问题:导包要一致,因为hibernate在spring中有3,4,5三个包


hibernate配置信息:


5、开启事务管理器


6、实例化hibernateTemplate(连接session,在dao层需要用它进行数据库操作)

 

(四) 将各层纳入spring管理,并持久化类

dao:


service:


action:


 大致ssh框架就整合完毕,一些简单的流程分享给大家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值