搭建SSH框架

Struts+hibernater+spring架构(myeclipse)

右击,首先加入spring,加入hibernater,再加入struts2

复制jar包(把tomcat发布的jar 复制到 lib) [copy以后可以移除struts2的引用]删除 asm2.2.3.jar,  antlr-2.7.2.jar,

Copy struts2-spring-plugin-2.1.8.1.jar 根据版本选择

一:

改web。Xml文件

 改web。Xml文件
<!-- 给context设置applicationContext.xml的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- 配置监听器 在启动程序的时候就加载spring配置文件并且会帮定到servlteContext里面 -->
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

二:

在spring 里面 加入action 的注入

三:

<!-- struts2 注入必须要加入 属性  scope="prototype"

默认 spring的对象都是单例模式的对象

加上scope="prototype"  那么就变成多实例了

struts2action不能做单例的 因为里面有form的值

-->

<bean id="fwxxaction" class="com.web.action.FwxxAction" scope="prototype">

<property name="fwxxservcie" ref="fwxxServcie"></property>

</bean>

四:-----------------…配置事务 看最下面 --------------------------------

五:----------------------…加入 过滤器-前提条件你配置事务-----------------------

 <filter>
<filter-name>sessionFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

注意:在action里面调用service 一定是一个接口的引用

如 UserService     而不是UserServiceImpl

六: Action 的配置

<!-- class 改为spring 配置文件中的id  那么就注入成功了 -->

<action name="fwxx" class="fwxxaction">

<result>/index.jsp</result>

</action>

下面为事务的配置 记得 改 那个表达式的位置哦……..

<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.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- 配置事物管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 配置实物传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="zhuangzhang" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice> <!-- 哪些类的那些方法参与 事物 -->
<aop:config>
<aop:pointcut id="allService" expression="execution(* service.*.*(..))"/>//表达式
<aop:advisor pointcut-ref="allService" advice-ref="txadvice"/>
</aop:config> </beans>

最后最关键的部分是 加入 struts2-spring-plugin-2.1.8.1.jar  注意版本号跟你的导入的struts2的版本相同

struts2-spring-plugin-2.1.8.1.jar 下载地址:http://i.cnblogs.com/Files.aspx 里面找。

myeclipse搭建SSH框架的更多相关文章

  1. 用MyEclipse搭建SSH框架(Struts2 Spring Hibernate)

    1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...

  2. MyEclipse8.5快速搭建SSH框架

    来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...

  3. [JavaEE] SSH框架笔记_eclipse搭建SSH框架详解

    SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一步:准备工作. 下载好eclipse,Struts2,Spring,Hibe ...

  4. Maven环境下搭建SSH框架

    © 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Maven:3.3.9 Struts2:2.5.10 Spring:4.3.8.RELEASE Hibernate:5.1.7.Fina ...

  5. Maven环境下搭建SSH框架之Spring整合Hibernate

    © 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Spring:4.3.8.RELEASE Hibernate:5.1.7.Final MySQL:5.7.17 注意:其他版本在某些特性 ...

  6. 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...

  7. eclipse Indigo搭建SSH框架详解

    SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一步:准备工作.   下载好eclipse,Struts2,Spring,Hi ...

  8. Java之基于Eclipse搭建SSH框架(下)

    在上篇博客里,我简介了Tomcat滴配置与Struts2滴搭建,假设对这个还不会滴童鞋去看一下我滴上篇博客<Java之基于Eclipse搭建SSH框架(上)>.今天我们接着上篇博客滴内容. ...

  9. MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程

    对Struts.spring.hibernate大体上了解一遍后,就是针对这个几个框架的整合了. 怎样整合,请看以下: 第一:Struts2的jar和xml配置文件: jar包: commons-fi ...

随机推荐

  1. Spring中加载多个Properties配置文件

    单个配置: <bean id="propertyConfigurer" class="org.springframework.beans.factory.confi ...

  2. In close() at SocketHttpClientConnection in Android

    In close() at SocketHttpClientConnection Error In Android. when i tried to acess network data on Mai ...

  3. Jmeter—5 关联 响应数据传递-正则表达式提取器

    在测试过程中,遇到一个问题:用户登录成功后服务器会返回一个登录凭证,之后所有的操作都需要带上此凭证.我们怎么获取登录凭证并传递给后续的操作? Jmeter提供了正则表达式提取器,用变量提取参数,后续通 ...

  4. SDR 研究

    最近终于买了一个RTL2832u 电视棒,可以软件无线电了 使用我的小米3开发板 (安卓6.0),直接在应用商店里搜索 "sdr",到豌豆荚中,就有“RTL驱动程序” 点击下载安装 ...

  5. CSS行内元素和块级元素的居中

    一.水平居中 行内元素和块级元素不同,对于行内元素,只需在父元素中设置text-align=center即可; 对于块级元素有以下几种居中方式: 1.将元素放置在table中,再将table的marg ...

  6. namenode需要升级

    java.io.IOException:File system image contains an old layout version -18.An upgrade to version -41 i ...

  7. Asp.net中Json的序列化和反序列化(一)

    JSON是专门为浏览器中的网页上运行的JavaScript代码而设计的一种数据格式.在网站应用中使用JSON的场景越来越多,本文介绍ASP.NET中JSON的序列化和反序列化,主要对JSON的简单介绍 ...

  8. 没有好看的 Terminal 怎么能够快乐地写代码

    换了好几回Terminal默认的配色,真是难看哭了,作为一只有生活追求的序媛,当然不能安(zuo)之(yi)若(dai)素(bi)了 1 自定义 Terminal问候语 sudo pico /etc/ ...

  9. 多媒体视频(video)

    <video> 是 HTML 5 中的新标签.<video> 标签的作用是在 HTML 页面中嵌入视频元素.<video> 标签定义视频,比如电影片段或其他视频流. ...

  10. CC3000 SPI接口编程介绍

    CC3000 SPI 操作: CC3000的SPI 是基于五根线CLCK,CSn,IRQ,MISO,MOSI:通信模式如下图: CLCK:时钟频率0-26M从主机到从机,提供SPI接口时钟 CSn:低 ...