Spring Hibernate 开启事务
2015-08-19 19:48
453 查看
仅仅记录一下配置文件
<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>
相关文章推荐
- Java基于数据源的数据库访问
- 详解。。java设计思想与设计模式------Beginer
- Java集合总览
- Struts(3)工作机制及分析
- Struts(2)环境搭建
- java 输出流和输入流
- Struts(1)初识Struts
- java 操作war文件
- java中将由数字组成的字符串型(String)转换成整型(int)
- Java IO流 装饰 字节流--19
- 快速生成java中的setter和getter
- Java记录
- 【Java】-基础-线程
- NIO(JDK1.4)--选择器Selector
- Ajax +SpringMVC 请求后台数据
- 在 Java 中如何更高效地存储和管理 SQL 语句?
- eclipse 终极操作技巧
- 在 Java 中如何更高效地存储和管理 SQL 语句?
- 安卓中eclipse不显示窗口与出现许多不认识的东西
- startexplorer插件 eclipse中项目文件快速定位到文件夹