Maven构建SpringMVC

1. 创建Maven-web项目

eclipse:File——New Project——Maven Project
Maven构建SpringMVC_第1张图片
第一项的Create a simple project(skip archetype selection)不要勾选,点击Next>
Maven构建SpringMVC_第2张图片
点选maven-archetype-webapp,然后Next>
Maven构建SpringMVC_第3张图片
输入Group Id、Artifact Id等信息,点击Finish,完成了Maven Web项目的创建。

  • eclipse新创建的Maven web项目有可能会jsp页面报错,解决方法:右键项目名——Build Path——Configure Build Path——在Libraries标签页中点击【Add Library…】
    Maven构建SpringMVC_第4张图片
    点选Server Runtime——Next
    Maven构建SpringMVC_第5张图片
    选中一个Tomcat服务——点击Finish——点击Apply and Close。
    Maven构建SpringMVC_第6张图片
  • eclipse新创建的Maven web项目有可能会缺少src/test文件夹,解决方法:右键项目名——Build Path——Configure Build Path——在Libraries标签页中选中JRE System Library——点击右侧的【Edit…】
    Maven构建SpringMVC_第7张图片
    ——选择Workspase default JRE——Finish——Apply and Close。
    Maven构建SpringMVC_第8张图片

2. 引入依赖

在pom.xml中添加下面两个SpringMVC的必备依赖

<dependency>
  <groupId>org.springframeworkgroupId>
  <artifactId>spring-webartifactId>
  <version>4.1.2.RELEASEversion>
dependency>
<dependency>
  <groupId>org.springframeworkgroupId>
  <artifactId>spring-webmvcartifactId>
  <version>4.1.2.RELEASEversion>
dependency>

3. 配置SpringMVC

你可能感兴趣的:(java,spring,maven)