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