SpringMVC+Spring+MyBatis 的综合练习 2 (搭建Maven环境)

2.1 在Eclipse中设置本地Maven

Maven选用的版本是3。我在本地装了一个,然后在Eclipse中设定了一下。
Eclipse中的本地Maven
Maven的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<localRepository>E:\GreenAPP\apache-maven-3.3.9\repo</localRepository>
	<mirrors>
		<mirror>
			<id>alimaven</id>
			<name>aliyun maven</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>
	<profiles>
		<profile>
			<id>jdk-1.8</id>
			<activation>
				<activeByDefault>true</activeByDefault>
				<jdk>1.8</jdk>
			</activation>
			<properties>
				<maven.complier.source>1.8</maven.complier.source>
				<maven.complier.target>1.8</maven.complier.target>
				<maven.complier.complierVersion>1.8</maven.complier.complierVersion>
			</properties>
		</profile>
	</profiles>
</settings>

##2.2 创建Maven项目

###2.2.1 Step by step

直接上图了。
Step 1
创建Maven项目 Step 1
Step 2
这里写图片描述

###2.2.2 修正错误

有两个地方不大对,

  1. jre的版本
  2. 缺少了web.xml文件和web项目的文件夹。

这里写图片描述

修复过程如下:

  1. 选中项目,右击,选择 properties,打开对话框。修改Java的版本。并且去掉Dynamic Web Module的勾。

这里写图片描述
2. 重新勾选Dynamic Web Module,选择3.0版本。点击 Further configuration available… ,打开对话框。

这里写图片描述
3. 输入文件夹,勾选 Generated web.xml deployment descriptor,点击OK。

这里写图片描述
4. 可以看见生成的web.xml文件和相应的文件夹。

这里写图片描述

##2.3 编写POM

###2.3.1 添加方法

在Maven的 仓库 中搜索需要添加的repository,选择版本,在详情页面中直接拖拽repository的信息到POM文件中就行了。每次保存POM文件,项目都会自动刷新jar包。
这里写图片描述

###2.3.2 POM中需要加入的jar包:

  • spring-webmvc : 4.3.13.RELEASE
  • spring-jdbc: 4.3.13.RELEASE
  • spring-aspects: 4.3.13.RELEASE
  • spring-test: 4.3.13.RELEASE [test]
  • mybatis : 3.4.5
  • mybatis-spring : 1.3.1
  • mybatis-generator-core : 1.3.5
  • mysql-connector-java : 5.1.41
  • c3p0 : 0.9.1
  • jstl : 1.2
  • servlet-api : 3.0
  • junit : 4.12 [test]

这些是目前建立项目所需要的,随着项目的继续,再不断完善和补充POM文件。

##2.4 POM文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.hh</groupId>
	<artifactId>ssm</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<dependencies>


		<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.3.13.RELEASE</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.3.13.RELEASE</version>
		</dependency>


		<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
			<version>4.3.13.RELEASE</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>4.3.13.RELEASE</version>
			<scope>test</scope>
		</dependency>


		<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.5</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.3.1</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
		<dependency>
			<groupId>c3p0</groupId>
			<artifactId>c3p0</artifactId>
			<version>0.9.1</version>
		</dependency>


		<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.41</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/jstl/jstl -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
		<!-- 注意:使用 SpringMVC 的仿真测试时,需要 servlet 3.0 -->
		<dependency>
		    <groupId>javax.servlet</groupId>
		    <artifactId>javax.servlet-api</artifactId>
		    <version>3.1.0</version>
		    <scope>provided</scope>
		</dependency>


		<!-- https://mvnrepository.com/artifact/junit/junit -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
		<dependency>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-core</artifactId>
			<version>1.3.5</version>
		</dependency>
	</dependencies>
</project>

到目前为止,项目的基本环境就算是告一段落了。下面要进行的是框架的配置。
(不着急,慢慢来,搞细致,记牢固)

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值