Spring Hibernate 开启事务

仅仅记录一下配置文件

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">


	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close" p:driverClass="com.mysql.jdbc.Driver"
		p:jdbcUrl="jdbc:mysql://hostname/test" p:user=""
		p:password="" p:maxPoolSize="200" p:minPoolSize="2"
		p:initialPoolSize="2" p:maxIdleTime="20"></bean>
		
		
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
		p:dataSource-ref="dataSource">

		<!-- annotatedClasses属性用于列出全部持久化类 -->
		<property name="annotatedClasses">
			<list>
				<!-- 以下用来列出Hibernate的持久化类 -->
				<value>com.songxu.entity.Log</value>
			</list>
		</property>
		<!-- 定义Hibernate的SessionFactory的属性 -->
		<property name="hibernateProperties">
			<!-- 指定数据库方言、是否自动建表、是否生成SQL语句等 -->
			<value>
				hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
				hibernate.hbm2ddl.auto=update
				hibernate.show_sql=true
				hibernate.format_sql=true
				#开启二级缓存
				hibernate.cache.use_second_level_cache=true
				#设置二级缓存的提供者
				hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
			</value>
		</property>




	</bean>






	<bean id="dao" class="com.songxu.entity.LogDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 开启事务 -->
	
	
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>


	<!-- 配置事务增强处理Bean,指定事务管理器 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<!-- 用于配置详细的事务语义 -->
		<tx:attributes>
			<!-- 所有以'get'开头的方法是read-only的 -->
			<tx:method name="get*" read-only="true"  />
			<!-- 其他方法使用默认的事务设置 -->
			<tx:method name="*" propagation="REQUIRED"/>
		</tx:attributes>
	</tx:advice>


	<aop:config expose-proxy="true">
		<!-- 只对业务逻辑层实施事务 -->
		<aop:pointcut id="txPointcut" expression="execution(* com.songxu.entity.*.*(..))" />
		<!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
		<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />
	</aop:config>



</beans>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值