整合步骤

  • 创建web工程
  • 引入相应的jar包
  • 整合spring和hibernate框架
  1. 编写实体类pojo和hbm.xml文件
  2. 编写bean-base.xml文件

<!-- 1) 连接池实例 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://mySqlCheck"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
        <property name="initialPoolSize" value="3"></property>
        <property name="maxPoolSize" value="6"></property>
    </bean>

    <!-- 2) SessionFactory实例创建 -->
    <!-- 所有的配置都由spring维护(项目中不需要hibernate.cfg.xml啦) -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- a. 连接池 -->
        <property name="dataSource" ref="dataSource"></property>
        
        <!-- b. hibernate常用配置: 方言、显示sql、自动建表等 -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        
        <!-- c. 映射配置 -->
        <property name="mappingLocations">
            <list>
                <value>classpath:cn/entity/*.hbm.xml</value>
            </list>
        </property>
    </bean>
    
    <!-- 3) 事务配置 -->
    <!-- # 事务管理器 -->
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- # 事务增强 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="*" read-only="false"/>
        </tx:attributes>
    </tx:advice>
    <!-- # AOP配置 -->
    <aop:config>
        <aop:pointcut expression="execution(* cn.service.*.*(..))" id="pt"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>
    </aop:config>

  3.编写bean-dao文件

  <bean id="employeeDao" class="cn.dao.EmployeeDao">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

  4.编写bean-service文件

  <bean id="employeeService" class="cn.service.EmployeeService">
        <property name="employeeDao" ref="employeeDao"></property>
    </bean>

  

  • 整合spring和struts2框架

  1.编写bean-action文件

  <bean id="employeeAction" class="cn.action.EmployeeAction"  scope="prototype">
        <property name="employeeService" ref="employeeService"></property>
    </bean>

  1.编写struts.xml文件

  <package name="emp" extends="struts-default">

        <!-- action实例交给spring容器创建 -->
        <action name="show" class="employeeAction" method="execute">
            <result name="success">/index.jsp</result>
        </action>

    </package>

  • 配置web.xml文件

  <!-- 配置spring的OpenSessionInView模式 【目的:JSp页面访问懒加载数据】 -->
    <!-- 注意:访问struts时候需要带上*.action后缀 -->
    <filter>
        <filter-name>OpenSessionInView</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInView</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>

    <!-- struts2配置 -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Spring配置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:bean*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

Struts2,Spring, Hibernate三大框架SSH的整合步骤的更多相关文章

  1. Struts2+Spring+Hibernate 三大框架的合并集成

    这次来看看Struts2+Spring+Hibernate三大框架的整合应用,主要是Spring和Hibernate框架的整合,因为前边已经将Strtus2+Spring整合过了基本一样.  首先看一 ...

  2. java 的 struts2 Spring Hibernate 三大框架的整合

    原理就不说了,直接上配置文件及代码,用来备用 首先,将三大框架所需要的jar包导入项目中 导入  struts2-spring-plugin-2.3.3.jar包  此包的作用是作为struts2 与 ...

  3. Struts2,Spring,Hibernate三大框架的整合(SSH)

    一.搭建struts2 1).导入struts2 jar包 2).编写web.xml 3).编写jsp页面 4).创建action类,action类要继承ActionSupport类 5).创建str ...

  4. Struts,spring,hibernate三大框架的面试

    Struts,spring,hibernate三大框架的面试 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3 ...

  5. Eclipse搭建SSH(Struts2+Spring+Hibernate)框架教程

    | 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 确实,刚创博客,对于这个陌生的东西还是有些许淡然.这是我的第一篇博文,希望能给你们有帮助,这就是我最大的乐趣! 好了下面进入正题: SS ...

  6. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

    1. 前言 最近在写毕设过程中,重新梳理了一遍SSM框架,特此记录一下. 附上源码:https://gitee.com/niceyoo/jeenotes-ssm 2. 概述 在写代码之前我们先了解一下 ...

  7. 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓

    hibernate工作原理 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6.提 ...

  8. [转] 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓

      hibernate工作原理 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6 ...

  9. ssh整合思想初步 structs2 Spring Hibernate三大框架各自要点

    Web层用Structs2的action Service层用Spring的IoC和aop以及JdbcTemplate或者Transaction事务(创建对象及维护对象间的关系) Dao层用Hibern ...

随机推荐

  1. Convert Excel data to MDB file

    所需组件: microsoft ado ext. 2.8 for ddl and security 或者更新的组件. 添加: using ADOX;using System.Runtime.Inter ...

  2. [Linux编程]__read_mostly变量含义

    1.定义 __read_mostly原语将定义的变量为存放在.data.read_mostly段中,原型在include/asm/cache.h 中定义: #define __read_mostly ...

  3. Selenium WebDriver 之 PageObjects 模式 by Example

    目录 1. 项目配置 2. 一个WebDriver简单例子 3. 使用Page Objects模式 4. 总结 5. Troubleshooting 6. 参考文档 本篇文章通过例子来阐述一下Sele ...

  4. 帝国cms 无法生成静态页

    建立目录不成功!请检查目录权限 安装完了帝国网站管理系统(帝国CMS)之后,没有进行初始化内置数据的步骤,而引起的错误.其实只要你按照安装说明一步一步下来就不会出错. 解决办法:初始化内置数据 帝国c ...

  5. NOIP复赛

    [代码为王] http://www.cnblogs.com/codeisking [洛谷] http://www.luogu.org/ NOIP2015 金币 扫雷游戏 求和 推销员 枚举 数学 优先 ...

  6. 初级Bug率,随时受不了

    一听到初级Bug这个名字,很多开发工程师都会觉得很头痛,还有那个“初级Bug率”,让人随时受不了. 初级Bug这个概念,在多数缺陷跟踪工具中,是不存在的,可以说是淘宝研发部的特色.初级Bug对应Bug ...

  7. Linux下的shell编程(三)BY 四喜三顺

    正则表达式:-------------------------------------------------------------------------------------------^   ...

  8. SQL Server 2008通过LinkServer连接MySQL

    链接过程就不过多描述了,搜索下都有一大堆的内容. 链接成功以后,如何调用的问题,通过“编写select脚本”的方式生成的脚本如下: [备注:asset_manager是数据库名,admin是表名] - ...

  9. CSS + DIV 让页脚始终底部

    一 前言 经常设计页面时用到三层DIV,头DIV与脚DIV一般固定高度,而中间层DIV根据内容的多少,高度不定,我们经常希望但内容很少时,脚DIV保持在底部,当内容很多时,脚DIV被中间内容挤到下面, ...

  10. 洛谷P1371 NOI元丹

    P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交  讨论  题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...