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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://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)框架项目教程相关推荐
- myeclipse搭建SSH框架
搭建SSH框架 Struts+hibernater+spring架构(myeclipse) 右击,首先加入spring,加入hibernater,再加入struts2 复制jar包(把tomcat发布 ...
- 用myeclipse搭建S2SH struts2 spring hibernate
step1: 在myeclipse上新建一个web项目 step2: 加入struts2所需的包 freemarker-2.3.16 ognl-3.0 struts2-core-2.2.1 strut ...
- 用myeclipse搭建SSH并做一个简单登录页面
SSH是(Struts,Spring,Hibernate)的简称. Struts进行流程控制,Spring进行业务流转,Hibernate进行数据库操作的封装. ·Struts 采用MVC模式,主要是 ...
- Eclipse+jetty+maven+Struts2+Spring2+Hibernate3+annotation注册系统V1.0
来源:http://www.blogjava.net/nkjava/archive/2009/03/29/262708.html 主要是整合了开发环境,同时也有一些不足,用deploy.bat可以方便 ...
- Eclipse搭建SSH环境实现Struts2分页显示mysql数据库表中内容
2019独角兽企业重金招聘Python工程师标准>>> 摘要 学习(Eclipse搭建SSH(Struts2+Spring3+Hibernate3)框架项目教程),尝试搭建ssh框架 ...
- maven hibernat mysql_手把手教你用 maven 搭建 SSH (struts2 +hibernate5 + spring5) 项目
手把手教你搭建 SSH 环境 一.项目环境搭建 1.1 配置 Spring 坐标依赖 1.2 配置 hibernate 坐标依赖 1.3 配置 struts2 坐标依赖 1.4 配置Java EE 坐 ...
- myeclipse部署ssh项目工程
为什么80%的码农都做不了架构师?>>> 今天利用myeclipse搭建了一个ssh框架,现在小编将详细的步骤写下来,以供搭建学习交流. 步骤阅读 工具/原料 myeclips ...
- ssh 框架引入service_搭建SSH开发框架时autowired注入为空的问题
最近在搭建SSH框架,使用@Autowired自动装配时,需要注入的对象是空,表明注入失败. 尝试了很多次还是不行,现在感觉可能是spring没配置好,所以类里的注解写对也注入不进去.但是从log4j ...
- eclipse搭建SSH框架详解
2019独角兽企业重金招聘Python工程师标准>>> SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一 ...
最新文章
- android中有关invisible,visible,gone的区别
- starGAN原理代码分析
- Memcache参数
- React学习:组件之间的关系、参数传递-学习笔记
- vuetify electron (开发环境及打包)
- c语言 子进程,子Shell和子进程
- ❤️万字总结八大排序:冒泡排序,选择排序,插入排序,堆排序,希尔排序,归并排序,计数排序❤️
- c和JAVA的安全编码_C、C++ 和 Java安全编码实践提示与技巧
- 2009年1月答疑帖
- 属于哪个单元_1~6年级上册数学第一单元知识整理
- validate使用
- MATLAB数学建模:智能优化算法-人工鱼群算法
- 聊聊我的Java自学之路
- 阿里图标库(iconfont)下载图标使用图标技巧(保姆级图文)
- 吃饭 睡觉 打豆豆游戏
- C语言学习1——C语言概述
- Osmo Mobile 教学
- cobar mysql5.6_Cobar init error
- Apriori算法Matlab实现
- 【毕业设计_课程设计】面向高考招生咨询的问答系统设计与实现(源码+论文)
热门文章
- 使用百度编辑器--ueditor,后台接收提交编辑的内容,HTML不见了, 赋值不了,赋值之后,html暴露出来了??...
- JavaSE-22 反射
- lintcode :sort letters by case字符大小写排序
- Scala学习笔记(二)表达式和函数
- 使用SPA/GPA 参数--SAP内存参数设置SET /GET PARAMTER ID
- 创建一个带有Lookup字段的List
- endnote style_教你在论文写作中玩转 Endnote
- linux查看都哪口状态,linux c 查看网口状态
- 大量数据table_一次 SQL 查询优化原理分析(900W+ 数据,从 17s 到 300ms)
- java ab性能测试,服务器JAVA性能测试——SPECjbb2005