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