如题所述
å¨applicationContext.xmléé¢å ä¸ä¸é¢çå
容
<!-- é ç½®äºå¡ -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- å¯ç¨æ³¨è§£ -->
<tx:annotation-driven transaction-manager="txManager"/>
åææ¯ä½ å·²ç»é 好äºsessionFactory
è¿æ ·å°±å¯ä»¥å¨éè¦å äºå¡çæ¹æ³ä¸å ä¸ @Transactional æ¥å ä¸äºå¡äºè¿½é®
<!-- é ç½®äºå¡ -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- å¯ç¨æ³¨è§£ -->
<tx:annotation-driven transaction-manager="txManager"/>
åææ¯ä½ å·²ç»é 好äºsessionFactory
è¿æ ·å°±å¯ä»¥å¨éè¦å äºå¡çæ¹æ³ä¸å ä¸ @Transactional æ¥å ä¸äºå¡äºè¿½é®
æ¬æ¥æç¨ç声æå¼äºå¡ï¼è½æ£å¸¸è¿è¡ãåæ¥æ¹æ注解就æ¥éï¼å°±æ¯è¿æ ·åçï¼ä¸ç¥é为ä»ä¹ãã
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-01-19
<bean id="transactionService"class="org.springframework. transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</<property>
<property name="target">
<ref local="transactionServiceControl"/>
</<property>
<property name="transactionAttributes">
<props>
<prop key=”insert*”>PROPAGATION_REQUIRED,-MyCheckedException</<prop>
<prop key=”update*”>PROPAGATION_REQUIRED</<prop>
<prop key=”*”>PROPAGATION_REQUIRED,readOnly</<prop>
</<props>
</<property>
</<bean>
<property name="transactionManager">
<ref local="transactionManager"/>
</<property>
<property name="target">
<ref local="transactionServiceControl"/>
</<property>
<property name="transactionAttributes">
<props>
<prop key=”insert*”>PROPAGATION_REQUIRED,-MyCheckedException</<prop>
<prop key=”update*”>PROPAGATION_REQUIRED</<prop>
<prop key=”*”>PROPAGATION_REQUIRED,readOnly</<prop>
</<props>
</<property>
</<bean>
第2个回答 2013-03-06
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置TransactionManager -->
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务策略 -->
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="productServiceMethods" expression="execution(* service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
</aop:config>
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置TransactionManager -->
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务策略 -->
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="productServiceMethods" expression="execution(* service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
</aop:config>
参考资料: