Spring Hibernate 开启事务

来源:互联网 发布:大数据工程师压力大吗 编辑:程序博客网 时间:2024/06/05 08:36

仅仅记录一下配置文件

<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/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://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.MySQL5InnoDBDialecthibernate.hbm2ddl.auto=updatehibernate.show_sql=truehibernate.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
原创粉丝点击