SPRINGMVC + MyBatis + Spring configuration Spring transaction processing

Source: Internet
Author: User

Today, configured for half a day, found that things do not work, the main error is as follows:

Org.mybatis.spring.transaction.SpringManagedTransaction]-[JDBC Connection [[email protected]] won't is managed by Sp  ringsqlsession [[email protected]] was wasn't registered for synchronization because synchronization are not activeclosing non Transactional sqlsession

Backstage to see the elephant's Bovencai find the answer, meaning is to expel the spring servlet to @service annotation scan, otherwise it will cause the thing configuration invalidation, filtering exclude @service annotations on the line.

Spring MVC starts with a configuration file that contains component scans, URL mappings, and set Freemarker parameters so that spring does not scan classes with @service annotations. Why do you set this up? Because Servlet-context.xml and service-context.xml are not loaded at the same time, if this is not done, spring will scan all classes with @service annotations into the container. When loading service-context.xml, because the container already exists service class, so that Cglib will not proxy service, the result is that the transaction configuration in Service-context does not work, when an exception occurs, the data can not be rolled back. In addition, the ability to parse the rest URL into a request map is the Defaultannotationhandlermapping class, which, at startup, @requestmapping annotations to all of the controller's methods, are put into a handlermapping object, when there is a request, it is in this object to find whether there is a matching path to the processing method, there is execution, will not output a not Page found warning message.

1 <!--define the Controller annotation scan package path, controller annotations are @Controller, you must exclude @service annotations-->2     <context:component-scan base-package= " Com.teshehui.product ">3         <context:include-filter expression=" Org.springframework.stereotype.Controller "Type=" annotation "/>4         <context:exclude-filter type=" annotation "expression=" Org.springframework.stereotype.Service "/>5     </context:component-scan>

SPRINGMVC + MyBatis + Spring configuration Spring transaction processing

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.