Spring + myBatis Common error: Annotation transaction does not roll back

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.