A. Declarative transaction configuration:
<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
<tx:advice id= "Txadvice" Transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "add*" propagation = "REQUIRED" read-only= "false"/>
<tx:method name= "del*" propagation= "REQUIRED" read-only= "false"/>
<tx:method name= "get*" propagation= "REQUIRED" read-only= "true"/> <tx:method "name="
propagation= "REQUIRED" read-only= "false"/>
</tx:attributes>
</tx:advice>
<AOP: config>
<aop:pointcut id= "servicemethods" expression= "Execution" (Public * com.lexing.platform.service.*. *(..))" />
<aop:advisor advice-ref= "Txadvice" pointcut-ref= servicemethods "/>"
</aop:config >
Two. Declarative transaction invalidation, reason
Root cause: An instance of the @service annotation was assembled by a child container scan.
The context of spring is a parent-child container in which the spring configuration file is loaded by Servletcontextlistener and the parent container is generated by the SPRINGMVC load configuration file. The Controller is assembled with an instance of the @service annotation (@Controller instance relies on the @service instance) when the child container scans the assembly, and the instance is supposed to be initialized by the parent container to guarantee the enhanced processing of the transaction. So at this time will be the original service (without a transaction to strengthen processing, so there is no transaction processing capacity.)
Three. Solutions
1.spring configuration file ApplicationContext:
<!--do not scan classes with @controller annotations, let SPRINGMVC child containers load.
<context:component-scan base-package= "Com.lexing.platform" >
<context:exclude-filter type= " Annotation "expression=" Org.springframework.stereotype.Controller "/>
</context:component-scan>
2.springMVC Config file servlet-context.xml
<!--class with @Service annotations is instantiated by the spring parent container, [@Service instance relies on @repository instances, so the spring parent container will also assemble @repository instances]
<context:component-scan base-package= "Com.lexing.platform" >
<context:exclude-filter type= " Annotation "expression=" Org.springframework.stereotype.Service "/>
</context:component-scan>