【Jsp精品源码栏目提醒】:网学会员为需要Jsp精品源码的朋友们搜集整理了三大框架整合 - 基础科学相关资料,希望对各位网友有所帮助!
本文介绍 Struts2spring2.5hibernate3 三大框架的整合,采用的是手动导入 jar 包的方式来整合三大框架,后续会写到使用 myeclipse 来自动整合三大框架的文章。
希望对这三大框架感兴趣,想用该三大框架整合开发项目的朋友有所帮助。
开发环境:IDE:MyEclipse9.0Servlet Container:Tomcat6.0DB:MySql5.0这里所用到的方式是:spring 用的是配置的方式 hibernate 用的是注解的方式。
1.到 Struts2、spring、hibernate 的官方网站下载
源码2.搭建开发环境3.新建 Web 项目4.导入 Struts2、Spring、Hibernate 整合时需要的 jar 包。
Struts2 安装包下的核心包下的(我这里的解压目录是 E:sshstruts-2.1.8.1lib)struts2-core-2.1.8.1.jarxwork-core-2.1.6.jarstruts2-spring-plugin-2.1.8.1.jarognl-2.7.3.jarfreemarker-2.3.15.jarcommons-fileupload-1.2.1.jarcommons-io-1.3.2.jarcommons-logging-1.0.4.jarhibernate 核 心 安 装 包 下 的 ( 我 这 里 的 解 压 路 径 是E:sshhibernate-distribution-3.3.2.GA-disthibernate-distribution-3.3.2.GA)hibernate3.jarlog4j-1.2.15.jarslf4j-api-1.5.10.jarslf4j-log4j12-1.5.10.jarE:sshhibernate-distribution-3.3.2.GA-disthibernate-distribution-3.3.2.GAlibrequired 下的antlr-2.7.6.jardom4j-1.6.1.jarjavassist-3.9.0.GA.jarjta-1.1.jarhibernate 注 解 安 装 包 下 的 ( 我 这 里 的 解 压 路 径 是E:sshhibernate-annotations-3.4.0.GAhibernate-annotations-3.4.0.GA)hibernate-annotations.jarE:sshhibernate-annotations-3.4.0.GAhibernate-annotations-3.4.0.GAlib 下的ejb3-persistence.jarhibernate-commons-annotations.jarSpring 安 装 包 下 的 ( 我 这 里 的 解 压 路 径 是E:sshspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6dist)spring.jarE:sshspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6libjakarta-commons 下的commons-collections.jarcommons-dbcp.jarcommons-fileupload.jarcommons-io.jarcommons-logging.jarcommons-pool.jarE:sshspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6libaspectj 下的aspectjrt.jaraspectjweaver.jarMySQL 需要的 jar 包mysql-connector-java-3.1.13-bin.jar5.书写配置文件web.xml 文件struts2org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterstruts2org.springframework.web.context.ContextLoaderListenercontextConfigLocation/WEB-INF/classes/applicationContext-.xmlindex.jspweb.xml 里面的配置基本上是固定写法。
Spring 配置文件Spring 配 置 文 件 的 模 板 可 到 源 码 里 进 行 拷 贝 , 我 这 里 的 路 径 是E:sshspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6-with-dependenciesspring-framework-2.5.6samplesjpetstorewarWEB-INFapplicationContext.xml我 这 里 是 写 了 多 个 spring 配 置 文 件 暂 时 分 的 是 applicationContext-util.xml 和applicationContext-bean.xml,applicationContext-util.xml 里 写 的 是 spring 的 主 要 配 置 内 容 ,applicationContext-bean.xml 里写的是所有关于实体类操作的配置。
applicationContext-util.xml 内容:classpath:db.propertiesdriversmysql.urlmysql.initialSizemysql.maxActivemysql.maxIdlemysql.maxWaitcom.balingke.bean..hibernate.showSQLhibernate.dialecthibernate.hbm2ddl