Problem Description:
Controller inside the method of service execution, the service method throws an exception, but does not follow the way the transaction is configured to roll back;
There is no problem with the service's transaction configuration;
The cause of this problem occurs:
The @service is not filtered out in the Springmvc-servlet.xml configuration file and is properly configured as follows:
<!--Automatic scan of package name - <Context:component-scanBase-package= "com.yrcn.my"> <Context:include-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller" /> <Context:exclude-filtertype= "Annotation"expression= "Org.springframework.stereotype.Service" /> <Context:exclude-filtertype= "Annotation"expression= "Org.springframework.stereotype.Repository" /> </Context:component-scan>
Cause resolution:
Org.springframework.web.context.ContextLoaderListener will load the @service in the project;
If you do not filter out the @service,spring container in Springmvc-servlet.xml, there will be two sets of @service beans;
We can print by debug, and you will find that the service bean inside the controller is not the same as the bean we obtained through beanfactory.
The service bean that we get through beanfactory can be rolled back correctly.
Springmvc+spring transaction cannot be rolled back