---
title: "struts2.1+spring2.5+hibernate3.3整合之第一步（spring2.5+hibernate3.3）"
author: "yaoweinan"
date: "2010-07-31T08:10:24Z"
tags: []
categories: ["企业架构"]
slug: "struts2-1-spring2-5-hibernate3-3-spring2-5-hibernate3-3"
draft: false
lastmod: "2010-07-31T08:10:24Z"
id: 725910
url: "https://ilyon.iteye.com/blog/725910"
---

<span style="color:darkred">***需要的.jar文件：***</span>
spring框架下的包：

![](http://dl.iteye.com/upload/attachment/286015/984170b7-b79b-3e45-af79-4300d1c472eb.png)
hibernate框架下的包:
![](http://dl.iteye.com/upload/attachment/286018/983d1228-9d86-3751-b963-357a488cedf8.jpg)
配置文件beans.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:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-2.5.xsd">
	<context:component-scan base-package="cn.com"/>
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
	<property name="driverClass" value="org.gjt.mm.mysql.Driver"/>
	<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/websystem?useUnicode=true&amp;charaterEncoding=UTF-8" />
	<property name="user" value="root"/>
	<property name="password" value="yaoweiwei"/>
	<!-- 初始化时连接池的最小连接 -->
	<property name="initialPoolSize" value="1"/>
	<!-- 连接池里最小连接数 -->
	<property name="minPoolSize" value="1"/>
	<!-- 连接池里最大连接数 default ：15 -->
	<property name="maxPoolSize" value="300"/>
	<!-- 最大空闲时间，60秒未使用则抛弃，default:0 永不抛弃 -->
	<property name="maxIdleTime" value="60"/>
	<!-- 连接池里连接耗尽时每次增加的数目 default：3-->
	<property name="acquireIncrement" value="6"/>
	<!-- 设置每60秒检查 所有连接池里的链接-->
	<property name="idleConnectionTestPeriod" value="60"/>
	</bean>
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
	<property name="dataSource" ref="dataSource"/>
	<property name="mappingResources">
		<list>
		<value>cn/com/bean/User.hbm.xml</value>
		</list>
	</property>
	<property name="hibernateProperties">
	<value>
		hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
		hibernate.hbm2ddl.auto=update
		hibernate.show_sql=false
		hibernate.format_sql=false
	</value>
	</property>
	</bean>
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
	<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	<!-- 基于注解方式配置事务 -->
	<tx:annotation-driven transaction-manager="txManager"/>
</beans>

用来测试生成表的o/m映射文件User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.bean">
	<class name="User">
		<id name="name" length="20"/>
		<property name="psw" not-null="true" length="20"/>
		<property name="sex" not-null="true" length="5">
		<type name="org.hibernate.type.EnumType">
		<param name="enumClass">cn.com.bean.Sex</param>
		<param name="name">12</param>
		</type>
		</property>
	</class>	
</hibernate-mapping>