SHH框架的搭建

本文详细介绍了如何搭建SHH框架,即整合Spring、Hibernate和Struts。首先,导入所需库文件,包括Struts2、Hibernate和Spring的相关包。接着,配置hibernate.cfg.xml和applicationContext.xml,进行Spring与Hibernate的整合,并通过测试验证整合成功。然后,解决Struts2版本冲突问题,最后配置Struts.xml和web.xml,完成整个框架的搭建并进行测试。
摘要由CSDN通过智能技术生成

建立一个Web项目,然后导入如下包

struts2包:在struts2-blank.war下的lib目录下,以及struts-2.3.15.1\lib下的struts和spring整合的插件包struts2-spring-plugin-2.3.15.1.jar

hibernate包:hibernate-distribution-3.6.10.Final\lib\,把required中的所有包都导入进去,以及jpa下的hibernate-jpa-2.0-api-1.0.1.Final,optional/ c3p0下的JDBC连接池c3p0-0.9.1.jar包,MYSQL的jdbc驱动mysql-connector-java-5.1.7-bin, hibernate的的一个日志系统,hibernate3.jar。

spring2.5:spring

 

在hibernate-distribution-3.6.10.Final\project\etc下找到一个hibernate.cfg.xml文件,拷贝到项目中的src下,去掉没用的部分。

添加applicationContext.xml文件。



1、整合SHH

首先整合spring和hibernate

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:aop="http://www.springframework.org/schema/aop" 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.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- 自动扫描与装配bean -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan>

<!-- 配置SessionFactory(与Hibernate整合) -->
<!-- 表示下面的变量是从这个配置文件读取的 -->
<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 在spring中配置了一个叫sessionFactory的bean,类为hibernate中的LocalSessionFactoryBean,这样,spring就和hibernate联系起来了 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
	<!-- 指定hibernate的配置文件的位置,classpath:hibernate.cfg.xml:配置文件的路径 -->
	<property name="configLocation" value="classpath:hibernate.cfg.xml"></property><!-- -->
	
	<property name="dataSource">
		<!-- 配置DataSource数据源,这里采用的是c3p0的数据库连接 -->
		<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
			<property name="jdbcUrl" value="${jdbcUrl}"></property>
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值