搭建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. 定时调度框架Quartz随笔

    最近项目中的定时批处理用到了quartz定时任务,在此记录下quartz的配置吧,一个小demo仅供参考,也方便自己今后复习! 下面直接来步骤吧! 一.首先,要搭起能让quartz正常运行的环境,至少 ...

  2. socket协议下如何缓存图片--推荐EGOCache

    EGOCache是一个轻量级的缓存框架.用法简单方便,在现在的项目中,我就用到EGOCache来缓存下载过的照片和字符串. 有人可能会问到,缓存照片还需要用EGOCache吗?AFNetworking ...

  3. JavaScript数组方法总结

    由于最近都在freecodecamp上刷代码,运用了很多JavaScript数组的方法,因此做了一份关于JavaScript教程的整理,具体内容如下: 一.普通方法 1.join() 将数组元素连接在 ...

  4. animate.css总结

    本文对animate.css的各个效果进行总结 bounce 从上掉落,在地上小幅度跳起 <!DOCTYPE html> <meta charset="utf-8" ...

  5. C++ 构造与析构函数

    这两个概念并不对等,构造函数可以完全控制成员构造过程(通过初始化列表),析构函数准确说应该叫析构之前被调用的函数 一般不应该手动调用析构函数:栈区对象会自动析构,堆区也是在delete的时候析构 有一 ...

  6. UE4 编译后 不能正常使用Open Level 打开关卡解决方案:Open Level Blueprint Node not workin

    配置DefaultEditor.ini 文件 [AllMaps] +Map=/关卡文件路径   参考文献: https://answers.unrealengine.com/questions/141 ...

  7. React Native使用AsyncStorage本地持久化

    AsyncStorage AsyncStorage是一个简单的,未加密的,异步的,持久化,关键值存储系统,是全局的.类似于iOS中的NSUserDefault. 存值: import { AppReg ...

  8. 收到远程通知,怎么区分是点击通知栏提醒进去的还是在foreground收到的通知?

    我现在是要区分点击通知栏的通知进入应用还是点击应用图标进入的,1,开始程序都是在后台.2,接受通知都是在foreground状态.applicationdidFinishLaunchWithOptio ...

  9. PCL安装使用

    一. 下载安装 http://pointclouds.org/downloads/windows.html 1. QT安装在默认路径下(否则后续会出现问题),添加环境变量QTDIR(c:\Qt\4.8 ...

  10. in_array 查询数组中是否存在某个值

    (PHP 4, PHP 5) in_array — 检查数组中是否存在某个值 说明 bool in_array ( mixed $needle , array $haystack [, bool $s ...