struts2.1.8+hibernate3.6.0+spring2.5三大框架整合demo
来源:互联网 发布:淘宝商城电脑版 编辑:程序博客网 时间:2024/06/05 18:48
1.打开myeclipse6.5,新建web工程:SSH
2.导入相关jar包
1)手动导入struts包,Struts2.1.8 最少依赖jar包7个,拷贝到/WEB-INF/lib目录下
在src目录下建立struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="SSH" extends="struts-default"> </package></struts>
配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" 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"><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
2)整合hibernate ,使用myeclipse6.5自动导入hibernate包,并生成hibernate.cfg.xml配置文件
3)整合spring ,使用myeclipse自动导入相关jar包,并生成applicationContext.xml配置文件
首先导入struts解压包lib目录下面的
注:默认读取applicationContext.xml文件的路径为 /WEB-INF 目录下, 而此时生成的applicationContext.xml文件位于src目录下面,因此需要在web.xml中配置一下路径:
<!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param>
同时需要在web.xml中配置一个监听
<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
4)导入mysql数据库链接jar包,和c3p0数据库连接池jar包
注:通过以上步骤导入jar包完成后,还有一步需要注意,去掉重复导入的jar包,工程名--》右键--》Properties
3.导入所需jar包之后,spring整合hibernate,配置applicationContext.xml文件中链接数据库等相关信息,这样hibernate.cfg.xml就可以不用了
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><!-- 整合hibernate 配置数据库链接相关信息 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"><property name="driverClass" value="com.mysql.jdbc.Driver"/><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssh?useUnicode=true&characterEncoding=UTF-8"/><property name="user" value="root"/><property name="password" value="root"/><!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 --><property name="initialPoolSize" value="1"/><!--连接池中保留的最小连接数。--><property name="minPoolSize" value="1"/><!--连接池中保留的最大连接数。Default: 15 --><property name="maxPoolSize" value="300"/><!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --><property name="maxIdleTime" value="60"/><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --><property name="acquireIncrement" value="5"/><!--每60秒检查所有连接池中的空闲连接。Default: 0 --><property name="idleConnectionTestPeriod" value="60"/></bean></beans>
5.完成以上步骤后进行一下检查,将项目部署到tomcat服务器上,启动服务器,如果服务器没有抛出异常信息,说明框架整合成功,接下来就可以在框架中添加代码了
目录结构
源码:http://pan.baidu.com/share/link?shareid=366896&uk=1141787684
- struts2.1.8+hibernate3.6.0+spring2.5三大框架整合demo
- 三大框架Struts2+Spring2.5+Hibernate3.5的整合开发
- Spring2.5+Struts2+Hibernate3整合之三
- Spring2.5+Struts2+Hibernate3整合之三
- spring2.5+struts2.1.8+hibernate3整合配置
- 整合struts2+hibernate3+spring2.5
- struts2.0、hibernate3、spring2.5框架整合流程实例
- 框架整合之--------spring2.5+struts2.1+hibernate3.6
- Struts2+Spring2+Hibernate3整合
- struts2.1.8+spring2.5+hibernate3.2+ext3.0框架整合笔记
- struts2.1.8+spring2.5+hibernate3.2+ext3.0框架整合笔记
- 整合Struts2+Spring3+Hibernate3三大框架实现淘宝商城
- spring2.5+struts2.18+hibernate3.5整合
- 整合Struts2+Spring2.5+Hibernate3.5
- 整合Spring2.5+Struts2.1+Hibernate3.2
- Struts2+Spring2.5+Hibernate3.3 整合总结
- Spring2.5+Struts2+Hibernate3整合之一
- Spring2.5+Struts2+ Hibernate3整合之二
- 启动vm报错failed to initialize KVM: Permission denie
- STM32-按键输入实验学习笔记
- java基础知识精华总结 java面试题 深圳酷琪 kuuqii.com 电脑配件软件 硬件一体化采购平台
- MySQL基础
- mybatis mapper.xml方法配置
- struts2.1.8+hibernate3.6.0+spring2.5三大框架整合demo
- 深入理解const char*p,char const*p,char *const p,const char **p,char const**p,char *const*p,char**const p
- Runnable 并不一定是新开一个线程
- 物联网的一些基础的东西
- chown -R david /home/david改变文件属主为david
- 自定义JSTL函数
- const 修饰
- Java复习 9.1问题???
- PowerDeisger使用心得〔MySql〕