SpringBoot 2.1.5.RELEASE官方文档学习笔记

1.System Requirements

最低Java8,也可以兼容Java11,对于Spring的版本Spring Framework 5.1.7.RELEASE 或者更高;下面是对于构建工具的版本要求。

Build Tool Version

Maven

3.3+

Gradle

4.4+

1.1 Servlet Containers

支持以下嵌入式的servlet容器

Name Servlet Version

Tomcat 9.0

4.0

Jetty 9.4

3.1

Undertow 2.0

4.0

也可以将springboot部署在任何servlet 3.1+兼容的容器中。

1.2 Getting Started

新建文件夹MySpringBoot,里面新建pom.xml


	4.0.0

	com.example
	myproject
	0.0.1-SNAPSHOT

	
		org.springframework.boot
		spring-boot-starter-parent
		2.1.5.RELEASE
	

	

然后,当前文件夹运行 mvn -package进行依赖下载和打包,也许会提醒,JAR包是空的,这个不要紧,毕竟我们现在还没开始写java内容。

[WARNING] JAR will be empty - no content was marked for inclusion!

1.3 Writing the Code

spring-boot-starter-parent提供了 dependency-management 部分,所以我们可以忽略依赖的版本标签,现在增加一个 spring-boot-starter-web依赖;


	
		org.springframework.boot
		spring-boot-starter-web
	

创建文件夹和文件 src/main/java/Example.java 

 

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class Example {

	@RequestMapping("/")
	String home() {
		return "Hello World!";
	}

	public static void main(String[] args) {
		SpringApplication.run(Example.class, args);
	}

}

1.3.1 The @EnableAutoConfiguration Annotation

SpringBoot的层级注解,The second class-level annotation is @EnableAutoConfiguration.

1.5 Creating an Executable Jar

创建一个可执行的jar包,只需要在pom中添加 spring-boot-maven-plugin 


	
		
			org.springframework.boot
			spring-boot-maven-plugin
		
	

然后运行  $ mvn package,If you look in the target directory, you should see myproject-0.0.1-SNAPSHOT.jar

$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar可以看jsr包里面的内容;

执行项目命令,如下

$ java -jar target/myproject-0.0.1-SNAPSHOT.jar

As before, to exit the application, press ctrl-c.

 

第一章starter就到这里了,接下来会介绍如何用。

你可能感兴趣的:(JAVA)