Spring MVC series (iii) spring + springMVC integration (annotation Mode)
I personally think that it is not very difficult to use the framework. The key is to understand its ideas, which is very helpful for us to improve programming. However, if you don't use it, you can talk about your thoughts on paper !!! First technology, then thinking. Practice.
1. Basic Concepts
1.1. Spring
Spring is an open-source framework. Spring was a lightweight Java development framework that emerged in 2003, it is derived from part of the concepts and prototype stated by Rod Johnson in his book "Expert One-On-One J2EE Development and Design. It is created to solve the complexity of enterprise application development. Spring uses the basic JavaBean to complete the previous tasks that may only be completed by EJB. However, Spring is not only used for server-side development. From the perspective of simplicity, testability, and loose coupling, any Java application can benefit from Spring. In short, Spring is a lightweight container framework for IoC and AOP.
1.2 SpringMVC
Spring MVC is a follow-up product of SpringFrameWork and has been integrated into Spring Web Flow. Spring MVC separates the roles of controllers, model objects, schedulers, and processing program objects, making them easier to customize.
2. Environment setup
2.1 introduce the corresponding package
The structure of springMVC and spring packages has undergone great changes. Each package is separated and flexible, requiring users to learn more deeply. When we introduce the package, based on the principle of "less", you can find the corresponding package based on the error. If there are too many packages, the packet will report errors and exceptions, which are difficult to distinguish. sprinMVC and spring are one of them, therefore, the introduced packages are basically the same as the architecture packages required by spring.
2.2 New Annotation xml file: springAnnotation-servlet.xml
2.3 create springxml file springAnnotation-core.xml
Interface implementation class to be called through bean Injection
2.3.1 ISpring Interface
public interface ISpring { public String get();}
2.3.2 ISpring implementation class
Public class SpringManager implements ISpring {@ Overridepublic String get () {// determines whether System is called. out. println ("------ I am springManager ----"); return "I am getMethod ";}}
2.3.3 SpringController class
Public class SpringController {// This replaces the process of configuring attributes in xml @ Resource (name = "springManager") private ISpring springManager; // inject springManager @ RequestMapping ("/spring/get") public String get () {System. out. println (springManager. get (); return "/success ";}}
The global configuration point of a project is in web. xml. You can view the framework used by a project in xml.
SpringMVC8
Index.html
Index.htm
Index. jsp
Default.html
Default.htm
Default. jsp
ContextConfigLocation
Classpath *: config/springAnnotation-core.xml
Org. springframework. web. context. ContextLoaderListener
SpringMVC
Org. springframework. web. servlet. DispatcherServlet
ContextConfigLocation
Classpath *: config/springAnnotation-servlet.xml
1
EncodingFilter
Org. springframework. web. filter. CharacterEncodingFilter
Encoding
UTF-8
ForceEncoding
True
EncodingFilter
/*
SpringMVC
/
Annotation: springMVC listens through dispastservlet. spring listens through linstener. The starting sequence between them is that the web Container has another one,
First, context-param
Second: Listerer
Third: Filter
Fourth: servlet
There is a certain relationship between the startup sequence.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHAgYWxpZ249 "center">
Summary
A picture is better than a thousand words!
Next , Please look forward to learning!