Spring自动代理配置事务

转自 http://www.sunxin.org

在使用Spring自动代理配置事务时,要配置TransactionAttributeSourceAdvisor(自动代理只能用于Advisor),该类需要一个事务拦截器(TransactionInterceptor)的引用。TransactionAttributeSourceAdvisor类提供了两种方式注入TransactionInterceptor对象,一种是通过构造器注入,一种是通过setter注入。当采用构造器注入时,运行良好;当采用setter注入时,则会抛出下列异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionAttributeSourceAdvisor' defined in class path resource [beans.xml]: Instantiation of bean failed; nested exception is java.lang.NullPointerException

Caused by: java.lang.NullPointerException

       at org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor$TransactionAttributeSourcePointcut.getTransactionAttributeSource(TransactionAttributeSourceAdvisor.java:102)

       at org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor$TransactionAttributeSourcePointcut.hashCode(TransactionAttributeSourceAdvisor.java:121)

       at java.lang.Object.toString(Object.java:209)

       at java.lang.String.valueOf(String.java:2577)

你可能感兴趣的:(java,spring,bean,xml)