Springmvc + mybatis + spring configuration, spring things, springmvcmybatis
After being configured for half a day today, we found that things are ineffective and the following error occurs:
org.mybatis.spring.transaction.SpringManagedTransaction] - [JDBC Connection [com.jolbox.bonecp.ConnectionHandle@120fc40] will not be managed by SpringSqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@47eb1b] was not registered for synchronization because synchronization is not activeClosing non transactional SqlSession
Only the elephant's blog post in the background can find the answer, which means that spring servlet scans @ service annotations. Otherwise, the configuration of things will fail and the @ service annotation will be filtered out.
The configuration file for Spring MVC startup, including component scanning, url ing, and setting freemarker parameters, so that spring does not scan classes with @ Service annotations. Why do we set it like this? Because the servlet-context.xml and service-context.xml are not loaded at the same time, if this setting is not done, spring will scan all classes with @ Service annotation into the container until the service-context.xml is loaded, because the container already has a Service class, cglib does not proxy the Service. The result is that the transaction configuration in service-context does not work and an exception occurs, data cannot be rolled back. In addition, the rest url can be resolved to the DefaultAnnotationHandlerMapping class for request ing. at startup, it puts all the methods marked with @ RequestMapping annotation in the Controller Into A HandlerMapping object, when there is a request, the object will be searched for whether there is a matching path processing method. If yes, if Not, a Not Page Found warning will be output.
1 <! -- Define the Controller annotation scan package path. The Controller annotation is @ Controller. The @ Service annotation must be excluded --> 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>
For details, see Spring MVC 3.0.5 + Spring 3.0.5 + MyBatis3.0.4. (2)