搭建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. samba服务--路径太深问题-转

  2. Spark随笔(三):straggler的产生原因

    首先,介绍前辈研究的基于MapReduce框架的outlier产生原因:其次,根据这些方面来分析Spark架构中的straggler:最后,根据阅览的优化办法,谈谈自己的看法. 一.MapReduce ...

  3. 网页版电子表格控件tmlxSpreadsheet免费下载地址

    tmlxSpreadsheet 是一个由JavaScript 和 PHP 写成的电子表格控件(包含WP插件, Joomla插件等等).. 程序员可以容易的添加一个类似Excel功能的,可编辑的表格功能 ...

  4. HDU 2089 不要62

    也是简单的数位dp. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  5. sass安装 使用

    一 什么是sass      sass是一种css开发工具.提供了很多便利的写法,使得css开发变得简单  易维护       sass有两种后缀名文件:一种后缀名为sass,不使用大括号和分号:另一 ...

  6. I.MX6 eMMC 添加分区

    /********************************************************************************* * I.MX6 eMMC 添加分区 ...

  7. [Spring] - Property注入

    使用Spring注入Properies文件方法: 1.src中新建一个settings.properties文件,内容如下: db_driverClassName=com.mysql.jdbc.Dri ...

  8. js中有趣的闭包(closure)

    一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量 ...

  9. Java笔记2-数据类型,变量,Java运算符

    我们编写软件,目的是为了高效的操作(增,删,改,查)数据. 数据类型 1.基本类型(8种)byte 字节型 -128~127short 短整型 -32768~32767int 整型 -21474836 ...

  10. D3 的优势

    可视化的库有很多,基于 JavaScript 开发的库也有很多,D3 有什么优势呢? (1)数据能够与 DOM 绑定在一起 D3 能够将数据与 DOM 绑定在一起,使得数据与图形成为一个整体,即图形中 ...