从零学习springboot(一)--环境搭建

1、安装springboot

1)首先检查jdk版本是1.8或更高版本。
java -version
2)jar依赖建议使用支持依赖管理功能的编译工具,这里使用maven建立工程
springboot是用maven3.2以及以上版本进行编译的
3)添加springboot依赖
典型的maven pom文件会集成自spring-boot-starter-parent工程并声明一个或多个starters
<1>典型场景
<?xml version="1.0" encoding="UTF-8"?>
<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.example </groupId>
<artifactId> myproject </artifactId>
<version> 0.0.1-SNAPSHOT </version>

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-parent </artifactId>
<version> 2.0.1.RELEASE </version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-web </artifactId>
</dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-maven-plugin </artifactId>
</plugin>
</plugins>
</build>

</project>
<2>如果不想使用 spring-boot-starter-parent,同时扔保持依赖管理的好处(非插件管理),可以通过使用 scope=import的依赖
<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<dependency>
<groupId> org.springframework.data </groupId>
<artifactId> spring-data-releasetrain </artifactId>
<version> Fowler-SR2 </version>
<type> pom </type>
<scope> import </scope>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-dependencies </artifactId>
<version> 2.0.1.RELEASE </version>
<type> pom </type>
<scope> import </scope>
</dependency>
</dependencies>
</dependencyManagement>
4)使用maven插件可以将工程打包为可执行jar
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-maven-plugin </artifactId>
</plugin>
</plugins>
</build>
5)查看工程依赖树
mvn dependency:tree

猜你喜欢

转载自blog.csdn.net/gosenkle/article/details/80187136
今日推荐