SpringBoot2入门:
一、为什么使用spring-boot2:
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
能快速创建出生产级别的Spring应用
springboot 的优点:
- Create stand-alone Spring applications
-
- 创建独立Spring应用
- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
-
- 内嵌web服务器
- Provide opinionated 'starter' dependencies to simplify your build configuration
-
- 自动starter依赖,简化构建配置
- Automatically configure Spring and 3rd party libraries whenever possible
-
- 自动配置Spring以及第三方功能
- Provide production-ready features such as metrics, health checks, and externalized configuration
-
- 提供生产级别的监控、健康检查及外部化配置
- Absolutely no code generation and no requirement for XML configuration
-
- 无代码生成、无需编写XML
SpringBoot是整合Spring技术栈的一站式框架
SpringBoot是简化Spring技术栈的快速开发脚手架
SpringBoot缺点
- 人称版本帝,迭代快,需要时刻关注变化
- 封装太深,内部原理复杂,不容易精通
如何学习Spring-Boot2(如何在官网学习)
二、系统要求
java 8 兼容 java14
maven3.3+
idea 2019.1.12(以上版本)
三、创建一个SpringBoot的项目
第一步:创建一个maven工程:
第二步:引入依赖:(版本自定义)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
第三步:创建主程序
/**
* 主程序类
* @SpringBootApplication:这是一个SpringBoot应用
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
第四步:编写业务代码
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(){
return "Hello, Spring Boot 2!";
}
}
第五步:测试:
直接运行main程序:在本地访问:http://localhost:8080/....
优点:
简化配置:所有的配置都可以在application.properties中进行配置
server.port=8888
简化部署:讲项目打包成jar包,在本地可以运行访问:(下附打包插件)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>