SPRINGMVC + Spring + MyBatis Learning Note: The solution that AOP transaction management doesn't work when SPRINGMVC and spring work together

Source: Internet
Author: User

System: WIN8.1

Database: Oracle 11GR2

Development tools: MyEclipse 8.6

Frames: Spring3.2.9, SpringMVC3.2.9, MyBatis3.2.8

Springmvc the Springmvc.xml file in the configuration scan package, do not include service annotations, Spring configuration file Configuration package Scan, do not include controller annotations, as follows:

Spring MVC configuration file:

<base-package= "package path">  <type = "Annotation" expression = "Org.springframework.stereotype.Service" /> </ Context:component-scan >

Spring's configuration file:

 1  <  context:component-scan  base-package  = "Package path"            >  2  <  context:exclude-filter  type  Span style= "color: #0000ff;" >= "Annotation"   expression  = " Org.springframework.stereotype.Controller " />  4  < / context:component-scan  >  

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?

Because Springmvc.xml and applicationcontext.xml are not loaded at the same time, if this is not the case, spring will scan all classes with @service annotations into the container until the load Applicationcontext.xml, because the container already exists the service class, so that Cglib will not proxy service, the result is that the transaction configuration in ApplicationContext does not work, when an exception occurs , the data cannot be rolled back.

SPRINGMVC + Spring + MyBatis Learning Note: The solution that AOP transaction management doesn't work when SPRINGMVC and spring work together

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.