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 ...
随机推荐
- vue 点击按钮弹窗,点击关闭按钮关闭弹窗。
<div @click="btnfc()">点击弹窗按钮</div> <div v-show="show"> <div ...
- spring踩坑
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- MySQL数据库文件
MySQL数据库文件 本文档从MySQL数据库和存储引擎层面介绍各种类型的文件. 参数文件(my.cnf) 错误日志(error log) 二进制日志文件(binary log) 慢查询日志(slow ...
- docker-compose文件语法解析(v3.x)
文件配置 compose文件是一个定义服务(service).网络(network)和卷(volume)的YAML文件 .Compose 文件的默认路径是 ./docker-compose.yml 提 ...
- linux 05
日期与时间命令:date.日历的命令:cal.计算器:bc 要使用quit退出 在命令行模式里执行命令时,会有两种主要情况: 一种是该命令会直接显示结果然后回到命令提示符等待下一个命令的输入 dat ...
- 树莓派 - RasberryPi推送数据到cloudMQTT
创建用户 在https://www.cloudmqtt.com/上创建一个帐户 转到右上角的控制面板 点击"创建"按钮 安装lib sudo pip install paho-mq ...
- 利用OpenXml读取、导出Excel
OpenXml是通过 XML 文档提供行集视图.由于OPENXML 是行集提供程序,因此可在会出现行集提供程序(如表.视图或 OPENROWSET 函数)的 Transact-SQL 语句中使用 OP ...
- webservice学习第一天
Webservice Webservice就是一种远程调用技术,他的作用就是从远程系统中获取业务数据 1 课程安排 l 什么是webservice l Webservice入门程序 l Webserv ...
- python协程有多厉害?
爬一个××网站上的东西,测算了一下协程的速度提升到底有多大,网站链接就不放了... import requests from bs4 import BeautifulSoup as sb import ...
- XV6操作系统接口
操作系统接口 操作系统的工作是(1)将计算机的资源在多个程序间共享,并且给程序提供一系列比硬件本身更有用的服务.(2)管理并抽象底层硬件,举例来说,一个文字处理软件(比如 word)不用去关心自己使用 ...