Spring container and spring MVC container
1. Question: why not use spring to manage all classes?
In our configuration of spring MVC, why does the controller not be directly managed by spring, but the spring MVC container should be managed separately
2. The relationship between spring container and spring MVC
Spring container is a parent-child relationship with spring MVC container. The child container can access the objects of the parent container, but the parent container can’t access the classes of the child container. If we scan all classes directly in the spring MVC configuration file and hand over service, Dao and controller to spring MVC for management, but if spring is used to manage contoller, it can’t access this class, because Co The ntoller is in the spring MVC container. If you configure spring to scan all classes directly, including controller, but do not configure spring MVC, the request sent by the server will have a 404 problem, because it can’t find the controller and spring can’t inject the controller
Example. Configure in applicationContext-service. <! -- Scan package to load Service implementation classes --> <context:component-scan base-package="com.easybuy"></context:component-scan> will scan for @Controller, @Service, @Repository, @Compnent Springmvc.Xml does not scan. Conclusion: springmvc. cannot provide services because there is no controller object in the springmvc subcontainer.
3. Why not directly SpringMVC.xml Scan all classes in?
In principle, we can leave the service, Dao and controller to spring MVC for management, and just let it scan all packages directly in the spring MVC configuration file. However, for the sake of future expansion, spring and spring MVC are configured separately, and spring manages the service, which is conducive to later expansion. Even if multiple struct2 are added in the future, the original configuration will not be affected
- Start tomcat server error Context initialization failed
- Solution: Spring no matching editors or conversion strategy found
- Springboot project startup exception – required a single bean, but 2 were found
- Several ways to check the IP address of raspberry pie
- Request cannot get static resource
- @Value gets the configuration file value and returns null
- linux docker Error Failed to get D-Bus connection: Operation not permitted
- Research on invalid modification of elementui component style
- Field userrepository in com.example.demo2.service.imp.UserServiceImp required a bean of type ‘com.ex
- Spring MVC realizes page upload file
- Springboot error: property ‘sqlsessionfactory’ or ‘sqlsessiontemplate’ are required error details
- How to realize automatic assembly in springboot
- (springmvc) Failed to load resource: the server responded with a status of 404 (Not Found)
- Can’t Dubbo’s @ service be injected into the spring container?
- Error creating bean with name ‘xxcontroller’
- Vscode configuration connection server docker write code
- Spring integrates JUnit configuration
- SQL injection for ASP + access website
- @Detailed description and code demonstration of qualifier
- shiro Error org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type