spring 与 hibernate 及事务的配置

来源:互联网 发布:邓超孙俪换脸哪个软件 编辑:程序博客网 时间:2024/05/09 09:47
 spring 与hibernate 及事务的配置:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.         xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
  4.         xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
  5.         xmlns:tx="http://www.springframework.org/schema/tx"
  6.         xsi:schemaLocation="
  7.             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  8.             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  9.             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  10.             http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
  11.             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
  12.             
  13.     <!-- Hibernate SessionFactory -->
  14.     <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  15.             <property name="dataSource">
  16.                 <ref bean="mysqldataSource1" />
  17.             </property>
  18.             <!--  
  19.             <property name="mappingResources">
  20.                 <list>
  21.                     <value>com/xh/hibernate/entity/User.hbm.xml</value>
  22.                 </list>
  23.             </property
  24.             -->
  25.             <property name="mappingLocations">
  26.                 <list>
  27.                     <!--value>classpath:/com/company/club/**/*.hbm.xml</value-->
  28.                 </list>
  29.             </property>
  30.             
  31.             <property name="hibernateProperties">
  32.                 <props>
  33.                     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  34.                     <prop key="hibernate.show_sql">true</prop>
  35.                     <prop key="hibernate.generate_statistics">true</prop>
  36.                     <prop key="hibernate.connection.release_mode">auto</prop>
  37.                     <prop key="hibernate.autoReconnect">true</prop>
  38.                 </props>
  39.             </property>
  40.     </bean>
  41.     <bean id="transactionManager"   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  42.         <property name="sessionFactory">
  43.             <ref local="hibernateSessionFactory" />
  44.         </property>
  45.     </bean>
  46.     <bean id="abstractTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
  47.         <property name="transactionManager" ref="transactionManager" />
  48.         <property name="transactionAttributes">
  49.             <props>
  50.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  51.                 <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
  52.                 <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
  53.                 <!--  prop key="set*">PROPAGATION_REQUIRED,timeout_80</prop-->
  54.                 <prop key="save*">PROPAGATION_REQUIRED,timeout_80</prop>
  55.                 <prop key="create*">PROPAGATION_REQUIRED,timeout_80</prop>
  56.                 <prop key="update*">PROPAGATION_REQUIRED,timeout_80</prop>
  57.                 <prop key="delete*">PROPAGATION_REQUIRED,timeout_80</prop>
  58.                 <prop key="*">PROPAGATION_REQUIRED</prop>
  59.             </props>
  60.         </property>
  61.     </bean>
  62. <!-- 
  63.     把事务配置在service层
  64.     <bean id="daoTarget" class="a dao class impl " lazy-init="true">
  65.         <property name="dataSource" ref="dataSource"/>
  66.     </bean>
  67.     <bean id="daoService" parent="abstractTransactionProxy">
  68.         <property name="target" ref="daoTarget"/>
  69.     </bean>
  70. -->
  71. </beans>
原创粉丝点击