1. 创建Maven-web项目
eclipse:File——New Project——Maven Project
第一项的Create a simple project(skip archetype selection)不要勾选,点击Next>
点选maven-archetype-webapp,然后Next>
输入Group Id、Artifact Id等信息,点击Finish,完成了Maven Web项目的创建。
- eclipse新创建的Maven web项目有可能会jsp页面报错,解决方法:右键项目名——Build Path——Configure Build Path——在Libraries标签页中点击【Add Library…】
点选Server Runtime——Next
选中一个Tomcat服务——点击Finish——点击Apply and Close。
- eclipse新创建的Maven web项目有可能会缺少src/test文件夹,解决方法:右键项目名——Build Path——Configure Build Path——在Libraries标签页中选中JRE System Library——点击右侧的【Edit…】
——选择Workspase default JRE——Finish——Apply and Close。
2. 引入依赖
在pom.xml中添加下面两个SpringMVC的必备依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>