<!-- ========================= GENERAL DEFINITIONS ========================= -->
<!-- Configurer that replaces ${...} placeholders with values from properties files -->
<!-- (in this case, mail and JDBC related properties) -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/conf/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<tx:advice id="transactionManagerAdivice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" isolation="READ_COMMITTED"
propagation="REQUIRED"
rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<!-- execution 里面的表达式表达的意思是impl下面的任何类,任何方法,(..)代表任意参数 -->
<aop:config>
<aop:pointcut expression="execution(* com.onecom.amp.plan.service.impl.*.*(..))" id="serviceId"/>
<aop:advisor advice-ref="transactionManagerAdivice" pointcut-ref="serviceId"/>
</aop:config>
2:配置以上部分就能实现事务了。不过有一点需要注意,你在使用回滚的时候一定要抛出runtimeException否则事务不会回滚