## 目录结构
![](https://box.kancloud.cn/d913a01f39e113f340fbe33d0b1b6f39_810x870.png)
## 配置
pom.xml:
~~~
UTF-8
1.8
1.8
5.0.2.RELEASE
org.springframework
spring-context
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
javax.servlet
servlet-api
2.5
provided
javax.servlet.jsp
jsp-api
2.0
provided
junit
junit
4.11
test
log4j
log4j
1.2.14
~~~
web.xml:
~~~
/p>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
Archetype Created Web Application
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation //加载配置文件
classpath:springmvc.xml //配置文件路径
1 //启动时机
dispatcherServlet
/
~~~
springmvc.xml:
~~~
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
~~~
HelloController:
~~~
package com.like.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController
{
@RequestMapping(path = "/hello")
public String hello()
{
System.out.println("hello springMVC");
return "success"; //该字符串默认为jsp文件名
}
}
~~~
## 启动流程
* DispatcherServlet对象被创建.
* springmvc.xml被加载.
* HelloController对象被创建.
## 访问流程
前端控制器最为重要.
![](https://box.kancloud.cn/dd728df81df60ffcac82896635bc8a6f_864x501.png)