一、准备
1、建立一个springBoot的maven项目(使用spring initailizr,或者建立一个maven后自己添加相关springBoot配置)
<!--版本管理相关-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<!--springboot基础依赖包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot打jar包专用插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2、添加相关mongoDB依赖,直接使用spring-data-xxx系列jar
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<!--spring-boot-starter-data-mongodb.jar 是在它的基础上进行的包装,
使用了很多默认配置-->