One, spring MVC and Spring integration when the instance was created two times solution 1. The cause of the problem
The spring MVC configuration file and the spring configuration file all use the scan annotations <context:component-scan base-package= "Com.study.springmvc"/>
2. Solution
2.1. There is no overlap between the packages scanned by the Spring IOC container and the SPRINGMVC IOC container, and the handler and Service/dao are placed under different packages
2.2. Use Exclude-filter and Include-filter subnodes to specify annotations that can only be scanned
Springmvc.xml configuration, limit only handle annotations @controller and exception handling annotations @controlleradvice
1 <Context:component-scanBase-package= "Com.study.springmvc"use-default-filters= "false">2 <Context:include-filtertype= "Annotation" 3 expression= "Org.springframework.stereotype.Controller"/>4 <Context:include-filtertype= "Annotation" 5 expression= "Org.springframework.web.bind.annotation.ControllerAdvice"/>6</Context:component-scan>
Spring configuration restricts annotations that do not scan handle annotations @controller and exception handling @controlleradvice
1 <Context:component-scanBase-package= "Com.study.springmvc">2 <Context:exclude-filtertype= "Annotation" 3 expression= "Org.springframework.stereotype.Controller"/>4 <Context:exclude-filtertype= "Annotation" 5 expression= "Org.springframework.web.bind.annotation.ControllerAdvice"/>6 </Context:component-scan>
Ii. relationship between the IOC container of Spring and the IOC container of the SPRINGMVC
The Bean in the SPRINGMVC IOC container can refer to the bean in the Spring IOC container, not the other way, because:
1.Spring MVC is a subclass of Spring, a subclass can reference a parent class, and a parent class cannot reference a subclass
2. From the software level, Spring MVC is the presentation layer can invoke the business layer, the business layer cannot invoke the presentation layer
SPRINGMVC Series (15) Spring MVC with spring integration when instances are created two times and the spring IOC container and SPRINGMVC's IOC container are connected