MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程
对Struts、spring、hibernate大体上了解一遍后,就是针对这个几个框架的整合了。
怎样整合,请看以下:
第一:Struts2的jar和xml配置文件:
jar包:
commons-fileupload-1.2.1.jar:文件上传
commons-io-1.3.2.jar:文件读取工具类
freemarker-2.3.15.jar:模板引擎。基于模板生成文本输出的通用工具。
ognl-2.7.3.jar:功能强大的表达式语言,替代EL表达式,进行数据绑定和显示
struts2-core-2.1.8.1.jar:struts2核心包
xwork-core-2.1.6.jar:xwork核心包,是struts2的底层核心
xml文件有:web.xml (配置struts2的核心过滤器)
struts.xml (配置资源訪问)
第二:Spring的jar和xml配置文件
jar包:
spring.jar:包括有完整公布模块的单个jar 包。可是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2.jar
commons-logging:针对日志处理的
aspectjrt:支持aop的jar
cglib-nodep-2.1_3:配合支持aop的jar
aspectjweaver.jsr 和 aspectjrt.jar:springAOP须要的包
xml文件有:applicationContext.xml
第三:Hibernate的jar和xml配置文件
jar包:
Hibernate3.jar:Hibernate的核心库
antlr-2.7.6.jar:运行HQL语句的支持包
cglib-asm.jar:CGLIB库,hibernate用它来实现PO字节码的动态生成
dom4j.jar: dom4j:Java的XML API
commons-collections.jar: Apache Commons包中的一个,包括了一些Apache开发的集合类,功能比java.util.*强大
commons-logging.jar: Apache Commons包中的一个,包括了日志功能
c3p0.jar: C3PO是一个数据库连接池,Hibernate能够配置为使用C3PO连接池。
jta.jar: JTA规范,当Hibernate使用JTA的时候须要
mysql-connector-java-5.1.5-bin.jar:链接mySql必须得包
xml文件有:hibernate.cfg.xml :针对每一个实体持久化所做的配置,数据库连接usernamepassword等等。
xx.hbm.xml:每一个实体相应一个
第四:Spring和Struts2、Spring和Hibernate整合时的XML配置和相关jar包
jar包:
Struts2和Spring整合时的jar:struts2-spring-plugin-2.1.8.1.jar是strus2和spring的一个整合插件。
Spring和Hibernate整合时不须要额外的jar包
xml配置:
1)Web.xml配置
<?xml version="1.0" encoding="UTF-8"? >
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 配置spring的用于初始化容器对象的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext*.xml
</param-value>
</context-param> <!-- ~~~~~~~~~~~struts2的配置 start~~~~~~~~~~~ -->
<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>
<!-- ~~~~~~~~~~~struts2的配置 end~~~~~~~~~~~ --> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>
2):Struts的Struts.xml配置
<? xml version="1.0" encoding="UTF-8" ? >
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts> <!-- 设置为开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- 扩展名配置为action -->
<constant name="struts.action.extension" value="action"/>
<!-- 主题,将值设置为simple,即不使用UI模板。 这将不会生成额外的html标签 -->
<constant name="struts.ui.theme" value="simple" /> </struts>
3)Spring的applicationContext.xml配置
<?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: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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!--导入外部properties文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 指定hibernate配置文件的位置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 连接池 -->
<property name="dataSource" >
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--mysql数据库驱动 -->
<property name="driverClass" value="${driverClass}"></property>
<!-- mysql数据库名称 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<!-- 数据库的登陆username -->
<property name="user" value="${user}"></property>
<!-- 数据库的登录password -->
<property name="password" value="${password}"></property>
<!-- 方言:为每一种数据库提供适配器,方便转换 -->
<!-- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> --> <!-- 其它配置 -->
<!--初始化时获取三个连接。取值应在minPoolSize与maxPoolSize之间。 Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保留的最小连接数。 Default: 3 -->
<property name="minPoolSize" value="3"></property>
<!--连接池中保留的最大连接数。 Default: 15 -->
<property name="maxPoolSize" value="5"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同一时候获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="3"></property>
<!-- 控制数据源内载入的PreparedStatements数量。假设maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。 Default: 0 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection" value="5"></property>
<!--最大空暇时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。 Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
</bean>
</property>
</bean> </beans>
4)Hibernate的hibernate.cfg.xml配置和xx.hbm.xml配置
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration>
<session-factory >
<!-- 方言:为每一种数据库提供适配器。方便转换 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property> </session-factory>
</hibernate-configuration>
xx.hbm.xml配置,就不用说了。
总结:
就这样,SSH框架整合完毕了,通过这些配置理解这个框架的设计和思想,这样才是最好的。
SSH框架整合好了,就通过一个实例检測下吧。见下篇博客。
MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程的更多相关文章
- 工作笔记3.手把手教你搭建SSH(struts2+hibernate+spring)环境
上文中我们介绍<工作笔记2.软件开发经常使用工具> 从今天開始本文将教大家怎样进行开发?本文以搭建SSH(struts2+hibernate+spring)框架为例,共分为3步: 1)3个 ...
- SSH(Struts2+Spring+Hibernate)框架搭建流程<注解的方式创建Bean>
此篇讲的是MyEclipse9工具提供的支持搭建自加包有代码也是相同:用户登录与注册的例子,表字段只有name,password. SSH,xml方式搭建文章链接地址:http://www.cnblo ...
- myeclipse搭建SSH框架
搭建SSH框架 Struts+hibernater+spring架构(myeclipse) 右击,首先加入spring,加入hibernater,再加入struts2 复制jar包(把tomcat发布 ...
- 用MyEclipse搭建SSH框架(Struts2 Spring Hibernate)
1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...
- SSH(Struts2+Spring+Hibernate)框架搭建流程
添加支持 我先介绍的是MyEclipse9的自带框架支持搭建过程:(完全的步骤 傻瓜式的学习..~) 首先我们来搭建一个Web项目: 一.Hibernate(数据层)的搭建: 相关描述 Ⅰ.服务器与数 ...
- 傅老师课堂:Java高级应用之Struts2+Spring2+Hibernate3大集成
开篇一笑:一对情侣,非常恩爱,但男友喜欢说脏话,一天女友提出要带男友回家吃个饭,见见家长,千叮万嘱让男友别说脏话,男友在家憋了一晚上没说一句脏话,天气寒冷,到走的时候女友家长要出来送他们,男友客气的说 ...
- SSH:Struts2.2+Hibernate3.6+Spring3.1分页示例[转]
参考资料 1 ssh分页(多个例子) http://useryouyou.iteye.com/blog/593954 2 ssh2分页例子 http://459104018-qq-com.iteye. ...
- 自练Eclipse搭建SSH全自动注解博客项目笔记
1.创建一个动态的java项目 2.导入搭建所需要的jar包 3.配置web.xml文件 1).头文件 2).struts2的拦截器 3).定位加载Spring容器的配置文件 4).监听 5). 6) ...
- SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)
这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...
随机推荐
- The MySQL server is running with the –secure-file-priv
show variables like '%secure%'; 将文件导出路径更改为查询到的secure-file-priv路径下 select * from table where column = ...
- centos 7 安装 docker(详细)
更新源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O/etc/yum.re ...
- POJ-2442-Sequence(二叉堆)
POJ-2442 Description Given m sequences, each contains n non-negative integer. Now we may select one ...
- nginx如何防止高负载造成服务器崩溃
nginx-http-sysguard模块 一.作用 防止因nginx并发访问量过高或者遭受攻击造成服务器宕机,可根据负载设置界面跳转. 二.安装配置 1.下载模块软件包 wget https:/ ...
- Django-模型层(1)
ORM MVC或者MTV框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置即可以轻松更换数据库,这极大的减轻了开发人员的工作 ...
- 【HIHOCODER 1575】 两个机器人(BFS)
描述 一个N × M的2D迷宫中有两个机器人.机器人A在迷宫左上角,只能向右或向下移动:机器人B在迷宫右下角,只能向左或向上移动.机器人不能移动到迷宫外.此外,由于奇怪的同步机制,这两个机器人只能同时 ...
- 大数据学习——安装zooleeper
1 alt+p,上传zookeeper-3.4.5.tar.gz 2 解压安装包 ,安装在apps目录下 tar -zxvf zookeeper-3.4.5.tar.gz -C apps 3 删除zo ...
- 图论trainning-part-1 D. Going in Cycle!!
D. Going in Cycle!! Time Limit: 3000ms Memory Limit: 131072KB 64-bit integer IO format: %lld Ja ...
- CodeForces - 592D Super M 题解
题目大意: 一棵树 n个点 有m个点被标记 求经过所有被标记的点的最短路径的长度以及起点(如有多条输出编号最小的起点). 思路: 1.当且仅当一个点本身或其子树中有点被标记时该点在最短的路径上因此,可 ...
- 可以学习相关框架【转:https://testerhome.com/topics/6283】
https://testerhome.com/topics/6283 单元测试方面(Java): Junit:本来想用我熟悉的testng,但是开发的同学说测试springmvc只能用Junit.所以 ...