Spring Boot简介

Spring Boot帮助你创建可以运行的独立的、基于Spring的生产级应用程序。 我们对Spring平台和第三方库采取了有主见的观点,这样你就能以最少的麻烦开始工作。 大多数Spring Boot应用程序只需要很少的Spring配置。

你可以使用Spring Boot来创建Java应用程序,可以通过使用 java -jar 或更传统的war部署来启动。

我们的主要目标是。

  • 为所有的Spring开发提供一个根本性的更快、更广泛的入门体验。
  • 开箱即用,但随着需求开始偏离默认值,请迅速摆脱困境。
  • 提供一系列大类项目常见的非功能特性(如嵌入式服务器、安全、度量、健康检查和外部化配置)。
  • 绝对没有代码生成(当不以原生镜像为目标时),也不要求XML配置。

第一个Spring Boot项目,可以通过从官网上下载一个jar文件,然后解压就可以直接运行了。

使用IDEA创建第一个demo

  1. 新建demo
  2. 选择依赖:

配置pom.xml文件。

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 http://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.1.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.didispace</groupId>
	<artifactId>chapter1-1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>chapter1-1</name>
	<description>快速入门</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>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

启动类:

java 复制代码
@SpringBootApplication
public class Chapter1Application {
	public static void main(String[] args) {
	SpringApplication.run(Chapter1Application.class, args);
	}
}

在当前包下创建一个控制类:

java 复制代码
// RestController = @Controller + @ResponseBody
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }
}

在src/resources下创建一个

application.properties

properties 复制代码
server.port=6453

启动Spring Boot项目,然后通过浏览器访问我们的第一个案例。

http://localhost:6453/hello

相关推荐
freellf8 天前
数据结构及基本算法
1024程序员节
BruceGerGer25 天前
flutter开发实战-flutter web加载html及HtmlElementView的使用
flutter·1024程序员节
网络冒险家2 个月前
【软考】系统集成项目管理工程师【第二版】
职场和发展·软考·集成学习·1024程序员节·系统集成项目工程师
BruceGerGer2 个月前
flutter开发实战-AssetBundle读取指定packagename的文件
flutter·1024程序员节
sheng12345678rui2 个月前
最新缺失msvcp140.dll的多种解决方法,有效解决电脑dll问题
windows·microsoft·电脑·dll文件·1024程序员节
a5553338203 个月前
电脑显示mfc140u.dll丢失的修复方法,总结7种有效的方法
java·经验分享·dll·dll文件丢失·1024程序员节
行十万里人生3 个月前
C++ 智能指针
linux·c++·git·阿里云·容器·蓝桥杯·1024程序员节
a5553338203 个月前
启动鸣潮提示错误代码126:加载d3dcompiler_43.dll错误或缺失的7个解决方法
前端·经验分享·dll·dll文件丢失·1024程序员节
BruceGerGer3 个月前
flutter开发实战-Webview及dispose关闭背景音
flutter·1024程序员节
BruceGerGer3 个月前
flutter开发实战-ListWheelScrollView与自定义TimePicker时间选择器
flutter·1024程序员节