整合步骤

  • 创建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. Async Programming - 1 async-await 糖的本质(1)

    这一个系列的文章主要来讲 C# 中的语言特性 async-await 在语言层面的本质,我们都知道 await 是编译器进行了一个 rewrite,然而这个 rewrite 并不是直接 rewrite ...

  2. java获取当前日期等以及时区

    代码: public static void main(String[] args) throws Exception{ /* * 获取当前时间的办法 */ //这个获取从1970年..直到现在的毫秒 ...

  3. Python format格式化输出

    http://www.jb51.net/article/63672.htm 推荐参考 >>> '{0},{1}'.format('hello','python') 'hello,py ...

  4. LeetCode 374. Guess Number Higher or Lower

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  5. 04-c#入门(类型转换)

    “无论是什么类型,所有的数据都是一系列的位,即一系列0和1.变量的含义是通过解释这些数据的方式来传达的.”——这句原话是书上翻译的,不过后一句话总感觉理解起来不是很通俗,自己觉得这样理解可能会合适些: ...

  6. JNI开发中String转换chat*工具

    char* Jstring2CStr(JNIEnv* env, jstring jstr) { char* rtn = NULL; jclass clsstring = env->FindCla ...

  7. C++设计模式-Adapter适配器模式

    Adapter适配器模式作用:将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 分为类适配器模式和对象适配器模式. 系统的数据和 ...

  8. .net网站能走多远

    刚写好了学校网站,请大家帮忙测试一下.不知道怎么sql注入,或者DDoS攻击,我也是大四什么都是摸索阶段,不过这个网站 做了好长时间了,现在终于可以上架了,希望大家能指点一二,谢谢! 地址:http: ...

  9. C#中如何定义全局变量及在各窗体中使用全局变量

    using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; us ...

  10. python 序列化 json pickle

    python的pickle模块实现了基本的数据序列和反序列化.通过pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,永久存储:通过pickle模块的反序列化操作,我们能够从文件 ...