The first three methods generally have to specify the specific module bean. If there are too many modules, for example, a large website usually has dozens of modules. We have to consider the fourth configuration method. The transaction proxy is automatically created.
Method 4: Configure declarative transactions as follows.
<beanid="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<propertyname="transactionManager">
<refbean="transactionManager"/>
</property>
<! -- Automatic proxy -->
<beanid="autoproxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<! -- It can be a Service or DAO layer, preferably for the business layer * Service) -->
<propertyname="beanNames">
<list>
<value>*Service</value>
</list>
</property>
<propertyname="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
Automatic proxy is also used in combination with regular expressions and advice.
<beanid="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<propertyname="transactionManager">
<refbean="transactionManager"/>
</property>
<beanid="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
<beanid="regexpMethodPointcutAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<propertyname="advice">
<refbean="transactionInterceptor"/>
</property>
<propertyname="pattern">
<value>.*</value>
</property>
</bean>
This method can intercept and process transactions for specific modules.