Tech

Spring 1.2 Java 5 Based Transaction Annotations

Colin Sampaleanu posted an excellent article on Spring 1.2’s Java 5 Based Transaction Annotations, if you want to follow this approach but don?t want the DefaultAdvisorAutoProxyCreator to pick up every available Advisor in the context, here what you can do

<bean name=”defaultAdvisor”
class=”org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator”>
<property name=”usePrefix” value=”true”/>
</bean>
<bean name=”defaultAdvisor.transactionAttributeSourceAdvisor”
class=”org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor”>
<property name=”transactionInterceptor” ref=”transactionInterceptor”/>
</bean>
<bean id=”transactionInterceptor”
class=”org.springframework.transaction.interceptor.TransactionInterceptor”>
<property name=”transactionManager” ref=”transactionManager”/>
<property name=”transactionAttributeSource”>
<bean
class=”org.springframework.transaction.annotation.AnnotationTransactionAttributeSource”/>
</property>
</bean>

Create you DefaultAdvisorAutoProxyCreator as mentioned but give it a name (defaultAdvisor in this case) and set the usePrefix property to true.

Then in all the advisors that you want to be picked up, change there name to have ‘defaultAdvisor.’ prefix.

The usePrefix property tells the DefaultAdvisorAutoProxyCreator to apply only those Advisors that have a prefix of its own name.

Alternatively you can also use the AdvisorBeanNamePrefix to tell the DefaultAdvisorAutoProxyCreator what prefix to consider.

2 thoughts on “Spring 1.2 Java 5 Based Transaction Annotations

Leave a reply to Alexwebmaster Cancel reply