方式1
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <import resource="classpath:applicationContext-dao.xml" /> <bean id="bbtForum" class="com.baobaotao.service.impl.BbtForumImpl" p:forumDao-ref="forumDao" p:topicDao-ref="topicDao" p:postDao-ref="postDao"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/> <aop:config> <aop:pointcut id="serviceMethod" expression="execution(* com.baobaotao.service.*Forum.*(..))" /> <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" > <tx:attributes> <tx:method name="get*" read-only="false"/> <tx:method name="add*" rollback-for="PessimisticLockingFailureException"/> <tx:method name="update*"/> </tx:attributes> </tx:advice> </beans>