Springmvc+spring transaction cannot be rolled back

Source: Internet
Author: User

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

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.