`
liuwenbo200285
  • 浏览: 12685 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring3.0+hibernate3.5整合那些事儿

阅读更多

很久没看spring和hibernate整合的东西了,正好赶上新项目,也搭个架子,就抽空学习了下,这里记录下来以便复习!

首先,下载spring和hibernate最新版本,最近都更新的挺频繁的,包也有点不同。(不明白为什么spring不出中文文档,虽然hibernate的有乱码,总算还能看的过去!)

其次新建一个普通的工程,创建applicationContext.xml文件,头文件命名空间什么的就直接从网上找别人的拷贝好了,没用myeclipse,不太方便,自己写出来也不太可能。(IE9怎么插入不了图片和代码?还是我级别太低?)

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

<!-- 注解需要用到的-->
<context:component-scan base-package="com.wenbo" />
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/manchat" />
<property name="user" value="root" />
<property name="password" value="2580233" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />

<!--hibernate注解需要改变的东西-->
<property name="annotatedClasses">
<list>
<value>com.wenbo.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.default_batch_fetch_size=8
hibernate.generate_statistics=true
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.wenbo.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>

 

 

最后贴上整合的时候在下载的包里找不到的不常用的jar

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics