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

Source: Internet
Author: User

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

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.