SpringBoot:
- 使代码变得简单,推荐使用注解
- 使配置变得快捷:具有自动配置、快速构建项目、快速集成第三方技术的能力
- 使部署变得便捷,具有自动配置、快速构建项目、快速集成第三方技术
提供了一系列starter pom 简化Maven依赖配置 - 使监控变得容易,自带项目监控
Maven
- 统一开发规范与工具
- 统一管理jar包
- properties元素
在<properties></properties>之间可以定义变量,以便在<dependency></dependency>之间引用
构建Maven项目:
1.配置SpringBoot核心启动器spring-boot-stater-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
2.添加starter模块
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.5.1</version>
</dependency>
环境搭建
通过main方法启动SpringBoot项目,不需要配置Tomcat
测试
编写测试代码
在src/main/java目录下,创建com.test包,并将在该报中创建TestController类
package com.test;
import……
@RestController
public class TestController{
@RequestMapping("/hello")
public String hello(){
return "Hello , SpringBoot!"
}
创建应用程序的APP类(启动类)
在com.test包中创建chapter3_1类:
package com.test;
import……
@SpringBootApplication
public class chapter3_1{
@RequestMapping("/hello")
public static void main(String[] args){
chapter3_1.run(chapter3_1.class,args);
}
}
启动之后,默认访问地址:http://localhost:8080/,
通过http://localhost:8080/hello访问项目,hello和测试类Controller中@RequestMapping(“/hello”)对应
网友评论