Springmvc + mybatis + spring configuration, spring things, springmvcmybatis

Source: Internet
Author: User

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)

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.