Spring Boot 简化了基于Spring的应用开发,只需要“run”就能创建一个独立的、生产级别的Spring应用。 Spring Boot为Spring平台及第三方库提供开箱即用的设置(提供默认设置,存放默认配置的包就是启动器starter),这样我们就可以简单的开始。多数Spring Boot应用只需要很少的Spring配置。
New-->Project
,选择Maven如下:GroupId、ArtifactId
spring-boot-starter-parent
的工程,里面已经对常用的各种依赖的版本进行了管理。所以只需以此作为项目的父工程即可。就不用担心各依赖版本之间冲突的问题了。jdk
版本,只需要简单的添加以下属性即可,如果不需要知道,则不添加。在pom.xml
文件中添加如下:
<properties>
<java.version>1.8java.version>
properties>
<parent>
<artifactId>spring-boot-starter-parentartifactId>
<groupId>org.springframework.bootgroupId>
<version>2.1.5.RELEASEversion>
parent>
pom.xml
文件中加入如下依赖:
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
dependencies>
spring-boot-starter-web
这个依赖自动引入的,而且所有的版本都已经管理好,不springboot-demo\pom.xml
<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.0modelVersion>
<groupId>com.tianjhgroupId>
<artifactId>springboot-demoartifactId>
<version>1.0-SNAPSHOTversion>
<properties>
<java.version>1.8java.version>
properties>
<parent>
<artifactId>spring-boot-starter-parentartifactId>
<groupId>org.springframework.bootgroupId>
<version>2.1.5.RELEASEversion>
parent>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
dependencies>
project>
package com.tianjh;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author tianjh
* @date 2021/3/22
* $Application springboot启动类
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
package com.tianjh.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tianjh
* @date 2021/3/22
*/
@RestController
public class HelloController {
@GetMapping("hello")
public String hello(){
return "hello, tianjh!";
}
}