Recent projects are using the Springmvc+spring+mybatis framework to find a transaction that cannot be rolled back when the transaction is configured.
The first configuration is as follows: Springmvc.xml configuration content:
Spring.xml Configuration Content
As seen from the above two profiles, I started by configuring the service in SPRINGMVC. However, the transaction annotations I configured in spring. Then there will be a problem. Because spring's containers (ApplicationContext) and SPRINGMVC (ApplicationContext) are different.
When the spring container is loaded, the parent container of the Servletcontextlistener (corresponding spring.xml) is loaded preferentially, and SPRINGMVC (corresponding springmvc.xml) produces a child container. The instance of the @service annotation assembled during the scan assembly of the sub-container controller is not processed by the transaction,
Service with no transaction capability. The service that the parent container initializes is a guarantee of the enhanced processing power of the transaction. If you do not remove the service from the child container, you will get a service with no transaction capability.
Therefore, we should put the scanning service work in the Spring.xml. Let the service and transaction annotations exist in the same container, so that the configured transaction annotations will work. That is to say <context:component-scan base-package= "com.services"/> This configuration from
Springmvc.xml in the configuration of the spring.xml. The problem of not rolling back a transaction can be solved.
Spring + myBatis Common error: Annotation transaction does not roll back