您的位置:首页 > 编程语言 > Java开发

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

2018-01-12 12:41 483 查看

2.1 在Eclipse中设置本地Maven

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



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>

4000
<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



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>


到目前为止,项目的基本环境就算是告一段落了。下面要进行的是框架的配置。

(不着急,慢慢来,搞细致,记牢固)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: