1.新建maven项目,选择webapp构建项目:
2.在新建的项目中src-main下新建两个目录,java和resources:
3.将java右键-marked directory as-Source Root,将resourcs右键-marked as-Resources:
4.在pom.xml中引入jar包:
<!-- 版本锁定 -->
<properties>
<spring.version>5.0.2.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
5.在WEB-INF下面的web.xml中配置前端控制器:
<servlet> <servlet-name>disPatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping> <servlet-name>disPatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
6.创建spring的配置文件:
7.配置服务器:
Run-Edit Configuration-Tomcat-Local:
将自己的项目加进去:
8.部署成功。