构建第一个springBoot项目最新版本2.2.5
参考:http://5180it.com:8080/bbs/admin/1/73.html
背景
在以前我们搭建一个web项目是比较繁琐,需要有一对的配置还要引入许多的第三方jar包,
而且我们需要了解jar包各个版本的区别以及依赖关系。
而springBoot的出现正为我们解决了这些烦恼。
构建工程
我们可以通过ide帮助我们去构建,但在这里我以官网线上构建的方式
在springBoot我们选择的是2.2.5版本,因为在mavne仓库中,发现2.2.5是最新的版本
在项目的配置下Project Metadata
Group可以理解为项目包路径
Artifact 可以理解为项目的名称
Options 可以配置项目的描述,打包的方式,以及jdk的版本,这里我们默认即可
在 Dependencies,我们可以添加需要的jar包引用,这里是构建第一个springBoot项目,我们引入spring-boot-starter-web即可,
该包包含web开发的常用配置,如@Controller、@RequestMapping 等
最后点击下方 Generate 生成项目即可
1、pom.xml的依赖
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.king</groupId>
<artifactId>fisrtSpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>fisrtSpringBoot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2、启动类
3、启动类
@SpringBootApplication 表示这是springBoot的项目,并标志启动项目入口
package com.king.fisrtSpringBoot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FisrtSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(FisrtSpringBootApplication.class, args);
}
}
4、controller
package com.king.fisrtSpringBoot;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/first")
public String first() {
return "hello world !";
}
}
参考资料:
http://5180it.com:8080/bbs/admin/1/73.html