The spring container first loads the parent container generated by Servletcontextlistener (corresponding applicationcontext.xml), and SPRINGMVC (corresponding Mvc_dispatcher_ Servlet.xml) produces a sub-container. The instance of the @service annotation assembled when the sub-container controller is scanned for assembly is not transacted, that is, a service with no transaction capability, and the service that the parent container initializes is a guarantee of the transaction's enhanced processing power. If the service is not exclude in the sub-container, the service with no transaction capability will be available at this time. Therefore, the service scan should not be included in the Spring MVC configuration file.
Spring MVC:
<Context:component-scanBase-package= "Com.pamirs.pradar.controller"> <Context:include-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller" /> <Context:exclude-filtertype= "Annotation"expression= "Org.springframework.stereotype.Service" /> </Context:component-scan>
Spring
<base-package= "Com.pamirs.pradar.controller"> < type= "annotation" expression= " Org.springframework.stereotype.Controller "/> </Context: Component-scan>
Add @transactional main attention to the issue:
<tx:annotation-driven/> looks for @Transactional on beans in the same application context it's defined in. This means, if you put <tx:annotation-driven/> a webapplicationcontext for a dispatcherservlet, it is only CHEC KS for @Transactional beans in your controllers, and not your services.
This means that,<tx:annoation-driven/> only looks for the @transactional annotation above the bean that is defined in the same application context file, and if you put it in the dispatcher application context, It only checks the @transactional annotations on the controller, not the @transactional annotations on your services.
I then defined the transaction configuration in the application context of Spring MVC (*-servlet.xml), @transactional the annotations on the controller, and finally the transaction worked.
Issues that spring + spring MVC may encounter