`
denyx123
  • 浏览: 42434 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Struts2 Spring3 hibernate3三个框架的集成

阅读更多
刚学SSH,现在来谈谈SSH的集成
首先是jar的导入,无可置疑要把SSH的jar包导入到lib下,还有数据库驱动包
接下来就是拷配置文件了,
1.修改web.xml

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>



    <welcome-file-list>

        <welcome-file>index.html</welcome-file>

    </welcome-file-list>

   

    <listener>

      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>


2.hibernate.cfg.xml

这个没什么好说的,配好就行了

3.Spring配置文件applicationContext-commons.xml<?xml version="1.0" encoding="UTF-8"?>

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

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>          

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.ret.dao.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>

这样hibernate就算集成好了,接下来是struts

4.web.xml

<package name="user" namespace="/" extends="struts-default" >
<action name="login" class="login" method="addUser">
<result>
<param name="success">/login.jsp</param>
<param name="error">/index.jsp</param>
</result>
</action>

</package>

5.applicationContext-actions.xml
<?xml version="1.0" encoding="UTF-8"?>

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


<bean name="login" class="com.ret.actions.UserAction" scope="prototype">
<property name="userDao" ref="userDao"/>
</bean>

</beans>

6.applicationContext-beans.xml

<?xml version="1.0" encoding="UTF-8"?>

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


<bean id="userDao" class="com.ret.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>
这样,三大框架就算集成完成了
初学,还望大家不吝赐教





分享到:
评论

相关推荐

    Struts2 Spring3 Hibernate4 框架完美整合

    这三个框架的整合,通常被称为SSH整合,可以提供一个高效、灵活且功能强大的企业级应用开发环境。 **Struts2框架**: Struts2作为表现层框架,主要负责处理HTTP请求和控制应用的流程。它基于MVC设计模式,提供了...

    struts+spring+hibernate三大框架整合

    SSH整合的关键在于如何优雅地将这三个框架集成在一起,让它们各自发挥优势,同时保持良好的解耦。Struts处理请求转发,Spring管理bean和事务,Hibernate负责数据库交互。通过Spring的IoC和AOP特性,可以有效地降低...

    struts2 spring hibernate框架技术与项目实战 光盘源码上

    开发者可以通过学习这些代码,了解如何配置和集成这三个框架,以及如何在实际项目中编写业务逻辑和数据库交互代码。此外,源码中可能还包含了一些基本的视图文件,如JSP或FreeMarker模板,展示了如何将后台处理的...

    struts2spring3hibernate3.3框架包.

    Struts2、Spring3和Hibernate3.3是Java Web开发中的三大主流框架,它们的集成使用可以构建出高效、稳定且可维护的Web应用程序。下面将详细介绍这三个框架以及它们的集成应用。 Struts2作为MVC(Model-View-...

    Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2

    Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2

    struts spring hibernate ssh 三大框架集成详细步骤 手把手教你搭框架

    SSH(Struts + Spring + Hibernate)框架集成旨在实现MVC(Model-View-Controller)设计模式,为业务逻辑、数据访问以及用户交互提供了高效的解决方案。 **Struts框架**: Struts是一个开源的MVC框架,负责处理用户...

    Struts+Spring+Hibernate框架概述

    下面将详细解释这三个框架的核心概念、功能以及它们如何协同工作。 **Struts框架**: Struts是MVC(Model-View-Controller)设计模式的一种实现,主要用于处理Web应用中的业务逻辑和展示逻辑。它提供了一个结构化的...

    struts2+spring4+hibernate

    本教程将深入探讨这三个框架如何协同工作,以实现高效、灵活和可扩展的电子商务平台。 首先,Struts2是一个基于MVC(Model-View-Controller)设计模式的Java Web框架,它提供了强大的请求处理和页面展示功能。...

    struts2 spring hibernate集成

    "mytest"可能是项目或测试目录的名字,这表明你可能已经有了一个包含这三个框架集成的示例项目。在这样的项目中,你通常会看到配置文件(如struts.xml、spring-context.xml、hibernate.cfg.xml),Action类,以及...

    struts+spring+hibernate实现图书修改和删除

    本项目通过SSH框架实现了图书管理系统的图书修改和删除功能,下面将详细介绍这三个核心组件以及如何整合它们来完成指定任务。 **Struts 2** Struts 2是一个基于MVC(Model-View-Controller)设计模式的开源框架,...

    struts+spring+hibernate

    此外,这个示例也展示了如何通过整合这三个框架,实现松耦合、可扩展且易于维护的Java Web应用。对于初学者来说,这是一个很好的起点,对于有经验的开发者,它可以作为一个参考模板,帮助他们在实际项目中快速搭建...

    struts+spring+hibernate(三大框架),外加ajax

    这个压缩包文件提供了一个使用这三个框架加上Ajax技术的详细实例,帮助开发者理解如何在实际项目中整合这些技术。 Struts是Apache组织开发的一款MVC(Model-View-Controller)框架,主要用于控制应用程序的流程。它...

    ssh(Struts2+hibernate+spring)三大开源框架的参考文档

    在实际开发中,这三个框架的集成可以极大地提高开发效率,同时降低系统的耦合度。 通过阅读这些参考文档,开发者不仅可以深入理解SSH框架的工作机制,还能学习到最佳实践和常见问题的解决方案。在阅读过程中,要...

    三大框架集成 struts2,spring,hibernate

    Struts2、Spring和Hibernate是...对于初学者,了解并实践这三个框架的集成,有助于深入理解Java Web开发的全貌,提升开发技能。通过实际项目练习,能够更好地掌握这些框架的使用和配合,为后续的高级开发打下坚实基础。

    struts2、hibernate和spring框架整合所需的jar以及配置文档

    SSH框架,即Struts2、Hibernate和Spring的组合,是Java Web开发中广泛...最后,确保所有的配置文件路径正确,导入的jar包完整,即可完成SSH框架的整合,从而在开发Java Web应用时,享受到这三个框架带来的便利和高效。

    最新项目系统:Struts2+Spring4+Hibernate4三大框架整合

    Struts2、Spring4和Hibernate4是Java Web开发中的三大主流框架,它们分别负责MVC模式中的表现层、业务层和服务层。这个最新的项目系统整合了这三个框架,旨在提供一个高效、灵活且易于维护的开发环境。下面将详细...

    Struts,Spring,Hibernate三大框架的面试&笔试题

    Spring还集成了众多第三方框架,构建了一个丰富的生态系统。 【Hibernate】 Hibernate是一个流行的ORM(对象关系映射)框架,用于简化Java应用与数据库之间的交互。其工作原理包括读取配置文件和映射信息,创建...

    struts+spring+hibernate整合

    Struts、Spring和Hibernate是Java Web开发中的三大主流框架,它们分别负责表现层、业务层和服务层的管理。Struts提供了MVC模式的实现,Spring则是一个全面的轻量级应用框架,包括依赖注入(DI)、面向切面编程(AOP...

    Struts2 Spring3 Hibernate3 整合必须包(很完整)

    Struts2、Spring3和Hibernate3是Java Web开发中的三个重要框架,它们分别负责MVC模式中的表现层、业务层和服务层。这三个框架的整合能够实现高效、灵活且可维护的Web应用程序。以下是对这三个框架及其整合的详细知识...

    struts2spring3hibernate3.3框架包

    使用这三个框架集成,开发者可以实现松耦合的架构,提高代码的可维护性和可测试性。Struts2处理前端请求,Spring3管理依赖和事务,Hibernate3.3负责数据持久化,共同打造一个强大的后端平台。在实际开发中,还需要...

Global site tag (gtag.js) - Google Analytics