what is Spring Boot?(spring Boot是什么?)
spring boot 能帮助你快速开发单机或生成级别的应用,spring平台及第三方库能帮你只需很少的配置快速开发,简单讲就是好用的开发框架。
Getting Started(初体验)
前置需要
1.Spring Boot 2.5.5 需要 Java 8
2.构建工具 :Maven 3.5 Maven – Welcome to Apache Maven
3.开发工具:Idea Download IntelliJ IDEA: The Capable & Ergonomic Java IDE by JetBrains
安装好jdk,maven,idea就可以开始了!
step1 创建一个新的工程,添加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>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
</parent>
<!-- Additional lines to be added here... -->
</project>
step2 添加依赖到classpath,开发web应用,把web-starter添加
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
step3 写代码,编写主类启动类
@RestController
@EnableAutoConfiguration
public class MyApplication {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
ok 可以启动了!idea 启动和debug启动两种均可以
然后可以尝试部署了,首先需要打包,创建一个可执行jar
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
执行mvn clear package 后生成可执行jar文件
java -jar XXX.jar 就可以启动应用。按ctrl-c便可以停止
.
好了入门成功!
目录
what is Spring Boot?(spring Boot是什么?)
1.为开发spring应用,快速开发,更容易入门。
2.开箱即用
3.为大工程提供很大范围的非功能性特征(例如容器嵌入,安全,度量指标,健康检查,外部配置)
4.绝对没有代码生成,也不需要XML配置。