搭建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. C# List和String互相转换

    List转字符串,用逗号隔开 List<string> list = new List<string>();list.Add("a");list.Add(& ...

  2. input , textarea 边框问题

    一.去掉边框: 看看基本的HTML: 复制代码 代码如下: <div class="wrap"> <input type="text" cla ...

  3. cd hit使用

    ~~和唐老师一个实验室的人开发的~~ CD-HIT is a very widely used program for clustering and comparing protein or nucl ...

  4. 地址(Address)——WCF学习笔记(2)

    地址(Address)分为: 统一资源表示(URI). EndpointAddress. 端口共享. 逻辑地址与物理地址. 请求监听与消息分发.

  5. HDU 1312 Red and Black (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...

  6. nvcc fatal : Cannot find compiler 'cl.exe' in PATH解决方法

    我在测试安装的deep learning工具theano.按照官网Baby Steps - Algebra一步步输入. >>> import theano.tensor as T & ...

  7. id 和 instancetype

    静态数据类型 默认情况下所有的数据类型都是静态数据类型 静态数据类型的特点: 1 在编译时就知道变量的类型 2 知道变量中有哪些属性和方法 3 在编译的时候就可以访问这些属性和方法 4 并且如果是通过 ...

  8. Visual Studio 启动修复命令

    今天VS启动不了了,连命令行的 devenv.exe /? 都执行不了,看不到帮助命令了,记性不好,以前看过但没记住呀,还好我装了两个不同版本的VS, 另一个VS的帮助命令还是可以看到的.虽然修复了, ...

  9. nginx入门到精通目录

    1.nginx入门篇 nginx安装与基础配置 nginx优化配置分析与说明 nginx模块结构 2.nginx功能篇 配置nginx的gzip功能 配置nginx的rewrite功能 配置nginx ...

  10. 简单的鼠标可拖动div 兼容IE/FF

    来源:http://www.cnblogs.com/imwtr/p/4355416.html 作者: 主要思路: 一个div,注册监听onmousedown事件,然后处理获取的对象及其相关值(对象高度 ...