上次折騰了半天,終于把延時(shí)加載配置好了。可是不配置事務(wù)總是覺得怪怪的。so..決定把事務(wù)也配置好。雖然是個(gè)小項(xiàng)目吧^_^.
<!-- 事務(wù)配置 -->
<!-- 事務(wù)管理器 用于hibernate的事務(wù)管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 事務(wù)攔截器 用于對攔截的方法開啟事務(wù),其中指定了一些只讀事務(wù)-->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*list">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="display*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*display">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*view">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="main*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- 自動(dòng)代理,配置使所有service層bean使用事務(wù)攔截器 -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean>
<!-- 事務(wù)配置結(jié)束 -->
簡單說明一下,其中是用了spring提供的
BeanNameAutoProxyCreator這個(gè)自動(dòng)代理服務(wù),自動(dòng)對名為XXXService的的bean使用使用攔截器開啟事務(wù),而在transactionInterceptor則定義了事務(wù)的屬性,限定了一些只讀的事務(wù)以提搞效率。