<!--事务拦截器,激活事务管理器所必须的bean--> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <!-- 事务拦截器bean需要依赖注入一个事务管理器 --> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <!-- 下面定义事务传播属性--> <props> <!--PROPAGATION_REQUIRE规则表示:在bean中所有以get开头的方法,当抛出异常时,自动回滚,并只读,其他异常自动回滚--> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean> <!--定义事务处理代理bean,他需要两个属性,一个是指定需要代理的bean,另一个是代理bean所需的事务拦截器--> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!-- 指定对满足哪些bean name的bean自动生成业务代理 --> <property name="beanNames"> <!-- 下面是所有需要自动创建事务代理的bean--> <list> <value>aaaManager</value> </list> <!-- 此处可增加其他需要自动创建事务代理的bean--> </property> <!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器--> <property name="interceptorNames"> <list> <!-- 此处可增加其他新的Interceptor --> <value>transactionInterceptor</value> </list> </property> </bean>