struts2.1+spring2.5+hibernate3.3整合之第一步(spring2.5+hibernate3.3)

17 篇文章 0 订阅
14 篇文章 0 订阅
[color=darkred][b][i]需要的.jar文件:[/i][/b][/color]
spring框架下的包:

[img]http://dl.iteye.com/upload/attachment/286015/984170b7-b79b-3e45-af79-4300d1c472eb.png[/img]
hibernate框架下的包:
[img]http://dl.iteye.com/upload/attachment/286018/983d1228-9d86-3751-b963-357a488cedf8.jpg[/img]
配置文件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&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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值