整合spring2.5+hibernate3+struts2.0
来源:互联网 发布:java 文件上传md5校验 编辑:程序博客网 时间:2024/05/21 09:35
之前有照着网上的博客教程整合了一个比这个更高版本的ssh2,但那时我只是照着做而已啦,对于只自学过strut2的小虾米来说,原理什么的都不懂,所以下定决心要学习一下其它两个框架。经过近一个月的自学过后,我按照视频的做法又来整合一个低版本的(因为视频是前几年的)下面是对我整合的一个记录。
jdk:1.7
tomcat:7.0
1.导入spring jar包
蓝色标注的是较新的两个jar包替换,因为jdk是1.7版本所以,这两个jar包就得换成新版本的,这个很重要,不然会报错的(我就出现错误才知道的)。
2.导入hibernate jar 包
蓝色的那个jar包,在strut2中也有,要选择最新版本。
3.导入数据库驱动jar包
这个千万别忘记啦
4.编写beans.xml文件
将sessionFactory交给spring管理,并由spring 管理连接数据库
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:annotation-config/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.gjt.mm.mysql.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/itcast?useUnicode=true&characterEncoding=UTF-8"/> <property name="username" value="root"/> <property name="password" value="qazwsx"/> <!-- 连接池启动时的初始值 --> <property name="initialSize" value="1"/> <!-- 连接池的最大值 --> <property name="maxActive" value="500"/> <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 --> <property name="maxIdle" value="2"/> <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 --> <property name="minIdle" value="1"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>com/sunnie/bean/Person.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=false hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=false hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider </value> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:annotation-driven transaction-manager="txManager"/> <bean id="personService" class="com.sunnie.service.impl.PersonServiceBean"/> <bean id="personList" class="com.sunnie.web.PersonAction"/> </beans>
5.编写bean,service,servicebean
6.单元测试
7.整合strut2 导入strut2jar包与spring整合sruts2jar包
总体jar包如下,好像挺多的,这里有些包还值得今后研究。
8.编写web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <!-- 对Spring容器进行实例化 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 解决因session关闭导致的延迟加载问题 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
9.之后就是写测试啦,struts.xml,action类,jsp页面,吼吼,完成。
这是我整个的项目可以下载哦。
1 0
- 整合spring2.5+hibernate3+struts2.0
- 整合struts2+hibernate3+spring2.5
- Struts2+Spring2+Hibernate3整合
- struts2.0、hibernate3、spring2.5框架整合流程实例
- spring2.5+struts2.18+hibernate3.5整合
- 整合Struts2+Spring2.5+Hibernate3.5
- Struts2.0+Spring2.0+Hibernate3.1整合
- Struts2+hibernate3.0+spring2.0整合
- struts2.0+spring2.0+hibernate3.1整合
- 整合Spring2.5+Struts2.1+Hibernate3.2
- Struts2+Spring2.5+Hibernate3.3 整合总结
- Spring2.5+Struts2+Hibernate3整合之一
- Spring2.5+Struts2+ Hibernate3整合之二
- Spring2.5+Struts2+Hibernate3整合之三
- Spring2.5+Struts2+Hibernate3整合之四
- Spring2.5+Struts2+Hibernate3整合之五
- Spring2.5+Struts2+Hibernate3整合之六
- Struts2.1.6 + Spring2.5+Hibernate3.2整合
- *POJ 3728 - The merchant(LCA‘ Tarjan)
- 关于苹果证书的一些理解
- java 项目中恢复Linux MySQL数据库sh
- 深入理解Hadoop集群和网络
- H.265与H.264
- 整合spring2.5+hibernate3+struts2.0
- 【Cocos游戏实战】功夫小子第七课之游戏主功能场景逻辑功能和暂停功能场景的分析和实现
- attribute与parameter区别
- java参数传递(传值与引用)
- hdu1016
- 恢复 rm -rf * 误删数据
- GCC 4.8编译程序抛出Error: no such instruction: `某某汇编指令`
- 集群之MYsql主从服务之引伸出Mysql互为主从(环形结构)
- 动态规划--循环数组最大子段和