myeclipse搭建SSH框架
搭建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框架的更多相关文章
- 用MyEclipse搭建SSH框架(Struts2 Spring Hibernate)
1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...
- MyEclipse8.5快速搭建SSH框架
来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...
- [JavaEE] SSH框架笔记_eclipse搭建SSH框架详解
SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一步:准备工作. 下载好eclipse,Struts2,Spring,Hibe ...
- Maven环境下搭建SSH框架
© 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Maven:3.3.9 Struts2:2.5.10 Spring:4.3.8.RELEASE Hibernate:5.1.7.Fina ...
- Maven环境下搭建SSH框架之Spring整合Hibernate
© 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Spring:4.3.8.RELEASE Hibernate:5.1.7.Final MySQL:5.7.17 注意:其他版本在某些特性 ...
- 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...
- eclipse Indigo搭建SSH框架详解
SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一步:准备工作. 下载好eclipse,Struts2,Spring,Hi ...
- Java之基于Eclipse搭建SSH框架(下)
在上篇博客里,我简介了Tomcat滴配置与Struts2滴搭建,假设对这个还不会滴童鞋去看一下我滴上篇博客<Java之基于Eclipse搭建SSH框架(上)>.今天我们接着上篇博客滴内容. ...
- MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程
对Struts.spring.hibernate大体上了解一遍后,就是针对这个几个框架的整合了. 怎样整合,请看以下: 第一:Struts2的jar和xml配置文件: jar包: commons-fi ...
随机推荐
- python操作excel表格详解(xlrd/xlwt)
http://www.2cto.com/kf/201501/373655.html http://blog.csdn.net/b_h_l/article/details/17001395 利用pyth ...
- JVM-程序编译与代码早期(编译期)优化
早期(编译期)优化 一.Javac编译器 1.Javac的源代码与调试 Javac的源代码放在JDK_SRC_HOME/langtools/src/shares/classes/com/sun/too ...
- C# winform中的datagridview控件标头加入checkbox,实现全选功能。
/// <summary> /// 给DataGridView添加全选 /// </summary> public class AddCheckBoxToDataGridVie ...
- iOS应用数据存储2-SQLite3数据库
SQLite3 SQLite3是一款开源的嵌入式关系型数据库,可移植性好,易使用,内存开销小. SQLite3是无类型的,意味着你可以保存任何类型的数据到任意表的任意字段中. SQLite ...
- RabbitMQ/JAVA (路由选择)
上篇博文中,我们建立了一个简单的日志系统.可以广播消息给多个消费者.本篇博文,我们将添加新的特性--我们可以只订阅部分消息.比如:我们可以接收Error级别的消息写入文件.同时仍然可以在控制台打印所有 ...
- BZOJ 2595 斯坦那树
很久以前就想做,后来弃坑了. 最近又在群里有人问了类似的问题,艾老师说是斯坦纳树(%%%) 就是状压DP,然后用Spfa对状态进行转移. #include <iostream> #incl ...
- SqlServer性能优化(一)
一:数据存储的方式: 1.数据文件:.mdf或.ndf 2.日志文件:.ldf 二:事务日志的工作步骤: 1.数据修改由应用程序发出(在缓冲区进行缓存) 2.数据页位于缓存区缓冲中,或者读入缓冲区缓存 ...
- 北京网赛I题 hiho1391 (树状数组、区间覆盖最大值问题)
题目链接:http://hihocoder.com/problemset/problem/1391 题意:A国和B国向对方分别投射N枚和M枚导弹(发射时间,飞行时间,伤害值),同时两国各自都有防御系统 ...
- hibernate内部测试题(附赠答案)
一.选择题(共25题,每题2.5分,选择一项或多项,漏选错选不得分) 1.在Hibernate中,以下关于主键生成器说法错误的是( ). A.increment可以用于类型为long.short或by ...
- Oracle数据库习题
以下习题都已Oracle数据库中默认表为主体 1.列出至少有一个员工的所有部门. SELECT DISTINCT D.DNAME FROM EMP E,DEPT D WHERE E.DEPTNO=D. ...