Content excerpt from: Springmvc Relationship to Spring context
Principle Difference
It is not clear that the Springmvc-servlet.xml configuration has a contextual relationship with the Spring.xml two configuration files. Finding a top article today is suddenly clear.
Specifically, the Spring.xml context and the springmvc-servlet.xml context are the parent-child container context, and they have the following relationship characteristics:
- The context defined by Spring.xml is the parent context and cannot invoke the context of the child container, that is, the springmvc-servlet.xml cannot be called;
- Springmvc-servlet.xml defines the sub-class to ask, you can call the parent container spring.xml context content;
Believe you see here, if you look at the Java Virtual Machine specification, it should be thought that this design is similar to ClassLoader's "Parental delegation Model".
Practical application
After knowing the principle difference, actually in the application, often has two kinds of modes:
Traditional type
The so-called traditional type, is the action, service, DAO Three layer architecture, based on the complex business of large company development model.
For this mode, the general spring context is controlled on the service, DAO two layer, and the thing integrity is also controlled at the service layer, while the Springmvc-servlet controls the action layer.
This result results in the following call relationships:
- Action can invoke service, DAO;
- Service, DAO cannot invoke action;
- The AOP of the spring context container cannot be applied to the action layer, but it can be done by defining it in Springmvc-servlet.xml.
Radical type
The so-called radical type, is to speed, do not write so many classes, do not use the traditional action, service, DAO three-layer mode, direct integration, docking reverse telecommuting, such as the speed of work can be considered.
For aggressive development, it's easy to use the sub-context of Springmvc-servlet.xml to manage all the content.
Springmvc context vs. Springcontext context