项目目录: application-config.xml(Spring核心配置文件):
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="myDataSource"/>
</bean>
<tx:advice id="buyAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="buyGoods" propagation="REQUIRED" isolation="DEFAULT"
rollback-for="java.lang.NullPointerException,
com.bjpowernode.excet.NotEnoughException"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="servicePt" expression="execution(* *..service..*.*(..))"/>
<aop:advisor advice-ref="buyAdvice" pointcut-ref="servicePt"/>
</aop:config>
java测试代码:
public static void main(String
[] args
){
String config
="application-config.xml";
ApplicationContext context
=new ClassPathXmlApplicationContext(config
);
BuyGoodsService buyGoodsService
=(BuyGoodsService
)
context
.getBean("buyService");
System
.out
.println("Main:"+buyGoodsService
.getClass().getName());
buyGoodsService
.buyGoods(1001,200);
}